Versions Compared

Key

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

...

This code uses == to compare two integer objects. From EXP03-J we know that for == to return true for two object references, they must point to the same underlying object. We thus deduce that the results of using the == operator in this code here will be misleading.

Code Block
bgColor#FFCCCC
public class TestWrapper2 {
 public static void main(String[] args) {
 
  Integer i1 = 100;
  Integer i2 = 100;
  Integer i3 = 1000;
  Integer i4 = 1000;
  System.out.println(i1==i2);
  System.out.println(i1!=i2);
  System.out.println(i3==i4);
  System.out.println(i3!=i4);
 
 }
}

...