...
Further confusion arises because the numerical comparison operators <
, <=
, >
, and >=
can be used with the numeric boxed types Byte
, Character
, Short
, Integer
, Long
, Float
, and Double
. In this case, auto-unboxing results in the numeric values contained in the boxed objects being compared, with the expected results (see JLS Section 5.6.2, "Binary Numeric Promotion"). When both arguments of a ==
or !=
operator are numeric boxed type, the equality operators are defined to be reference equality operators; the operation is thus a reference comparison rather than the anticipated numeric comparison, which may produce unexpected results (see EXP03-J. Do not use Avoid the equal and not equal operators to compare when comparing boxed primitives).
Noncompliant Code Example
...