posted 1 year ago
The Appendix (Chapter 2: Operators, Answer #13) says:
"The first expression is evaluated from left to right since the operator precedence of & and ^ is the same, letting us reduce it to false ^ sunday, which is true, because sunday is true."
However, the & operator has higher precedence than the ^ operator and not the same one. That's why the statement
"boolean goingToTheStore = sunny & raining ^ sunday;"
evaluates "sunny & raining" first andit can be reduced to false ^ sunday.
Evidence:
System.out.println(true ^ true & false); // true
System.out.println((true ^ true) & false); // false
If the operators & and ^ have the same precedence and the statement "true ^ true & false" is evaluated from left to right, the result would be false and not true.
Am I right?
Peter Prazenica