in java are Logical Xor and Bitwise Xor share same ^
I tried to looked at my java book and seems so. So strange?
in java are Logical Xor and Bitwise Xor share same ^
I tried to looked at my java book and seems so. So strange?
It's both, depending on the operands.
When both operands of an operator &, ^, or | are of a type that is convertible (§5.1.8) to a primitive integral type ...
or in other words, two integral operands result in a bitwise XOR.
0 1
0 0 1
1 1 0
or JLS 15.22.2:
When both operands of a &, ^, or | operator are of type boolean or Boolean, then the type of the bitwise operator expression is boolean.
false true
false false true
true true false
It isn't at all strange for operators to perform different functions depending upon operands - consider addition versus string concatenation. 2 + 2
and "Hello " + "world!"
are clearly two different kinds of operations.