&&
is supposed to have higher precedence than ||
:
int a = 10;
System.out.println(a==10 || --a==9 && a==8);
System.out.println(a);
this prints true, and 10. It seems that it checks only the first part and if its true the second never executes.
If I do a==9
then the second part seems to evaluate and prints 9. Can someone explain why this is happening? Isn't &&
supposed to evaluate first?
Edit: I see it. a==10 || --a==9 && a==8
transforms into (a==10) || (a==9 && a==8)
So if the first one evaluates to true it short circuits. Thank you for your help guys.