boolean a = true; boolean b = true; boolean c = false; System.out.println(a || b && c); // true System.out.println(b && c || a); // true
I recently discovered that, in my opinion, there is a little oddity here. Why && and || are at different priority levels? I would suggest that they were on the same level. This demonstrates the above. both statements are true, although an estimate from left to right gives false for the first and true for the second.
Does anyone know the reasons for this?
(By the way, I would just use parentheses here, but it was the old code that raised the question)
java operator-precedence
Cogman
source share