Versions Compared

Key

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

...

These comparisons generate the output sequence: true, false, false and true. The cache in the Integer class memoizes integer values from -127 to 128 only, which explains the output of the above code. Avoid this problem by using the equals() method instead of == to compare wrapper classes. See guideline EXP03EXP01-J for further details.

Compliant Solution

...