I have a simple code below:
public class Foo {
public static void main(String[] args) {
boolean v = true;
v = v || hello();
System.out.println(v);
}
public static boolean hello() {
System.out.println("inside hello");
return true;
}
}
and it prints:
true
But if I change the expression:
v = v || hello();
to
v |= hello();
It prints:
inside hello
true
Can anyone please explain why this is happening? I assumed that they should have identical behavior but in case of |=
operator, the short-circuit is not happening.