Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 the equal and not equal operators to compare boxed primitives).

Noncompliant Code Example

...