Those are the bitwise AND and bitwise OR operators.
Indeed when both inputs are boolean, the operators are considered the Boolean Logical Operators and behave similarly to the Conditional-And (
int a = 6; // 110
int b = 4; // 100
// Bitwise AND
int c = a & b;
// 110
// & 100
// -----
// 100
// Bitwise OR
int d = a | b;
// 110
// | 100
// -----
// 110
System.out.println(c); // 4
System.out.println(d); // 6
The Java Language Spec(15..22.1,15.22.2) regarding the different behaviors of the operator based on its inputs.Indeed when both inputs are boolean, the operators are considered the Boolean Logical Operators and behave similarly to the Conditional-And (
&&
) and Conditional-Or (||
) operators except for the fact that they don't short-circuit so while the following is safe:if((a != null) && (a.something == 3)){
}
This is not:if((a != null) & (a.something == 3)){
}
Comments
Post a Comment