...
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:
...