62,634
社区成员




public class TestAlll {
public static void main(String[] args) {
Integer a = 12;
Integer a2 = 12;
if(a == a2 ){
System.out.println("1111111111");
}
Float ff = 1.0f;
Float fb = 1.0f;
if(ff == fb){
System.out.println("2222222222");
}
String str1 = "1123321";
String str2 = "1123321";
if(str1 == str2){
System.out.println("3333333333333");
}
Double df = 1.0;
Double db = 1.0;
if(df == db){
System.out.println("4444444444444");
}
}
}
private static class IntegerCache {
private IntegerCache(){}
static final Integer cache[] = new Integer[-(-128) + 127 + 1];
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Integer(i - 128);
}
}
public static Integer valueOf(int i) {
final int offset = 128;
if (i >= -128 && i <= 127) { // must cache
return IntegerCache.cache[i + offset]; //从上面static内部类的cache中读取缓存的对象
}
return new Integer(i);
}
public static Double valueOf(double d) {
return new Double(d);
}