It is directly inspired by this question .
There are many references / claims that the bitwise operators applied to Boolean will not be closed. Thus, in other words boolean a = f() & g(), where f(), and g()both return a Boolean value, the two will always be evaluated.
However, JLS only says:
15.22.2 Logical logical operators &, ^ and |
When both operands are a &, ^ or | operator are of type boolean or Boolean, then the type is a bitwise operator expression of boolean. In all cases, the operands are unpacked (Section 5.1.8), if necessary.
For &, the result value is true if both operand values are true; otherwise the result will be false.
For ^, the value of the result is true if the values of the operand are different; otherwise the result will be false.
For | the result value is false if both operand values are false; otherwise the result is correct.
How does this ensure that both operands are actually evaluated? Besides xor, you can still break and return the result if one of the arguments (and it can be second / right , which will be first evaluated) violates the condition.
For instance. a & byou only need to evaluate bto false to evaluate the expression to false. Please note: I do not ask if it is implemented in this way (does not close) - of course.
I'm asking:
Will it be implemented in case of a short circuit to violate the standard language?
source
share