...
| Code Block |
|---|
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);
   Â
 }
}
|
Output of this code
| Code Block |
|---|
true false false true |
It is because that in JDK 5.0, if the value p being boxed is true, false, a byte, an ASCII character, or an integer or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2. And the reason for this rule explained in criterion for autoboxing:
...