I have got confused due to what is true regarding the operator precedence in Java. I read in tutorials a long time ago that AND has a higher priority than OR, which is confi
Because of the short-circuit &&, the expression is evaluated as though there were parentheses around (y < 2) | doStuff() ...
This statement is incorrect, indeed meaningless. The fact that && is a short-circuit operator has nothing to do with the evaluation of (y < 2) | doStuff(), and indeed that could only compile if doStuff() returned a Boolean. What makes the difference (the implicit parentheses) is the precedence of && relative to |, which is defined in JLS ##15.22-23 as && being lower.
That's because it is using the |
operator instead of ||
, which has a higher priority. Here's the table.
Use the ||
operator instead and it'll do what you think.