Versions Compared

Key

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

Java defines equality operators == and != for objects. Naive programmers often confuse the intent of the == operation with that of the Object.equals() method. This confusion is frequently seen in the context of String processing.

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. However, auto-unboxing is not applied when the equality operators == and != are used with these numeric boxed types, so the object references are compared, which may produce unexpected results.

Noncompliant Code Example

...