62,615
社区成员
发帖
与我相关
我的任务
分享
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);
}
}
return IntegerCache.cache[i + offset]; //缓存处理
这句代码不是很明白能否详细说明一下
int tm = m.intValue();
tm--;
m = Integer.valueOf(tm);
int tn = n.intValue();
tn--;
n = Integer.valueOf(tn);
public static Integer valueOf(int i) {
final int offset = 128;
if (i >= -128 && i <= 127) { // must cache
return IntegerCache.cache[i + offset]; //缓存处理
}
return new Integer(i);
}
Integer m = new Integer(2);
Integer n = new Integer("2");
m--;
n--;
private final int value; //用于保存被包装进Integer对象中的整数
public Integer(int value) {
this.value = value;
}
public Integer(String s) throws NumberFormatException {
this.value = parseInt(s, 10); //用字符串解析成的整数初始化value
}
public int intValue() {
return value;
}
int tm = m.intValue();
tm--;
m = new Integer(tm);
int tn = n.intValue();
tn--;
n = new Integer(tn);
public class AutoWrapping {
public static void main(String[] args) {
Integer i = 100;
Integer j = 100;
System.out.println(i == j);
Integer m = 129;
Integer n = 129;
System.out.println(m == n);
}
}
public static Integer valueOf(int i) {
final int offset = 128;
if (i >= -128 && i <= 127) { // must cache
return IntegerCache.cache[i + offset];
}
return new Integer(i);
}