Things are more like they are now than they ever were before.
--Dwight D. Eisenhower
If the operands of an equality operator are both of either reference type or the null type, then the operation is object equality.
A compile-time error occurs if it is impossible to convert the type of either operand to the type of the other by a casting conversion (§5.4). 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. The contents of two strings s
and t
can be tested for equality by the method invocation s.equals(t)
(§20.12.9). See also §3.10.5 and §20.12.47.