I thought I understood that using short circuit operators that the order of precedence is important however I am having difficulty in understanding why the following code occurs:
line 3. false && true || true // this returns true
line 4. false && true | true // this returns false
I am correct in stating that the code on line 4 will return false because the evaluation is from right to left. However if line 3 has the left to right evaluation, why does it return a true? Using just two short circuit operators is fine but using three, I am somewhat stuck on the logic. No pun intended.
Remember operator precedence in Java.
|is evaluated before&&, but||is evaluated after&&. Therefore, the first one would evaluate as(false && true) || truewhich would equaltrue, while the second one would evaluate asfalse && (true | true), which evaluates to false.