This is directly inspired by this question.
There are numerous references/statements that bitwise operators, when applied to booleans, will not short circuit. So in other words boolean a = f() & g()
, where f()
and g()
both return boolean, both always will be evaluated.
However, JLS says only:
15.22.2 Boolean Logical Operators &, ^, and |
When both operands of a &, ^, or | operator are of type boolean or Boolean, then the type of the bitwise operator expression is boolean. In all cases, the operands are subject to unboxing conversion (§5.1.8) as necessary.For &, the result value is true if both operand values are true; otherwise, the result is false.
For ^, the result value is true if the operand values are different; otherwise, the result is false.
For |, the result value is false if both operand values are false; otherwise, the result is true.
How this warrants that both operands are actually evaluated? Apart from xor
, you are still able to break and return result if one of arguments (and it may be second/right being first to be evaluated) violates condition.
Eg. a & b
would need only to evaluate b
to be false to evaluate the expression to false.
Please note: I'm not asking if it is implemented this way (does not short circuit) -it certainly is.
I'm asking:
Would implementing it with short circuit violate language standard?