62,635
社区成员




public class Test{
public static void main(String[] args){
Integer a = 100 ;
Integer b = 100 ;
Integer a2 = 200;
Integer b2 = 200;
System.out.println (a==b);
System.out.println (a2==b2);
}
}
public class Test {
public static void main(String[] args) {
Integer a = 100; //自动包装(或叫自动装箱)
Integer b = 100; //编译器会将其处理成 Integer b = Integer.valueOf(100);
Integer a2 = 200;
Integer b2 = 200;
System.out.println (a == b);
System.out.println (a2 == b2);
}
}
public static Integer valueOf(int i) {
final int offset = 128;
//注意下面的这个 if,如果在 -128 ~ 127 间就用缓冲的 Integer 对象的引用作返回值
if (i >= -128 && i <= 127) { // must cache
return IntegerCache.cache[i + offset];
}
return new Integer(i);
}