example code of the problem:
\
error:
I try to do this to reduce repetition of my code but it doesn't work. I want to use take variable to represent either pop or serve. Is there a way to make this work? This might looks unnecessary but the real code I am having problem is quite long and it looks very repetitive if I put them in if else block. Instead of putting the return statement into if else block, I want to set a variable of the method instead.