Java Reference
In-Depth Information
It is a compile-time error if it is impossible to convert the type of either operand to the type
of the other by a casting conversion (§
5.5
). The run-time values of the two operands would
necessarily be unequal.
At run time, the result of
==
is
true
if the operand values are both
null
or both refer to the
same object or array; otherwise, the result is
false
.
The result of
!=
is
false
if the operand values are both
null
or both refer to the same object or
array; otherwise, the result is
true
.
While
==
may be used to compare references of type
String
, such an equality test determines
whether or not the two operands refer to the same
String
object. The result is
false
if the
operands are distinct
String
objects, even if they contain the same sequence of characters
vocation
s.equals(t)
.
15.22. Bitwise and Logical Operators
The
bitwise operators
and
logical operators
include the AND operator
&
, exclusive OR
operator
^
, and inclusive OR operator
|
.
AndExpression:
EqualityExpression
AndExpression
&
EqualityExpression
ExclusiveOrExpression:
AndExpression
ExclusiveOrExpression
^
AndExpression
InclusiveOrExpression:
ExclusiveOrExpression
InclusiveOrExpression
|
ExclusiveOrExpression
These operators have different precedence, with
&
having the highest precedence and
|
the
lowest precedence.
Each of these operators is syntactically left-associative (each groups left-to-right).
Each operator is commutative if the operand expressions have no side effects.
Each operator is associative.
The bitwise and logical operators may be used to compare two operands of numeric type
or two operands of type
boolean
. All other cases result in a compile-time error.