WEIRD DIFFERENCE: int popped = stack.pop() vs stack.pop() in if statement

We have

   Stack<Integer> stack = new Stack<>();
   Stack<Integer> minStack = new Stack<>();

The following generates an error, how come?

            if (stack.pop() == minStack.peek())
			
			// Also fails:
			 Integer popped = stack.pop();   
              if (popped == minStack.peek()) {

But this succeeds, its so weird!!

            int popped = stack.pop();
            if (popped == minStack.peek()) {

Also I tested this and it works, why is that??

        if (stack.pop().equals(minStack.peek())) {

Comments (3)