the unary NOT operator has higher precedence that that of the logical OR operator (||).
Yes it's true. But the precedence thing will come into effect, if you use NOT on the first expression of logical OR.
Consider the condition:
if (!x.equals(y) || y.equals(z))
In this case, the negation will be applied first on the result of x.equals(y)
, before the logical OR. So, had the precedence of ||
been greater than !
, then the expression would have been evaluated as:
if (!(x.equals(y) || y.equals(z)))
But it's not. As you know why.
However, if the NOT operator is on the second expression, the precedence is not a point here. The first expression will always be evaluated first before the 2nd expression. And short-circuit behaviour will come into play.