So for binary operators on booleans, Java has &, |, ^, && and ||.
Let's summarize what they do briefly here:
- JLS 15.22.2 Boolean Logical Operators &, ^, and |
- JLS 15.23 Conditional-And Operator &&
- JLS 15.24 Conditional-Or Operator ||
For
&, the result value istrueif both operand values aretrue; otherwise, the result isfalse.For
|, the result value isfalseif both operand values arefalse; otherwise, the result istrue.For
^, the result value istrueif the operand values are different; otherwise, the result isfalse.The
&&operator is like&but evaluates its right-hand operand only if the value of its left-hand operand istrue.The
||operator is like|, but evaluates its right-hand operand only if the value of its left-hand operand isfalse.
Now, among all 5, 3 of those have compound assignment versions, namely |=, &= and ^=. So my question is obvious: why doesn't Java provide &&= and ||= as well? I find that I need those more than I need &= and |=.
And I don't think that "because it's too long" is a good answer, because Java has >>>=. There