public class Main{
public static void main(String[] args){
Integer num1 = 100;
Integer num2 = 100;
Integer num3 = 200;
Integer num4 = 200;
'''//输出结果'''
System.out.println(num1==num2);
System.out.println(num3==num4);
}
}
public static Integer valueOf(int i) {
assert IntegerCache.high >= 127;
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + 128];
return new Integer(i);
}
'''// IntegerCache,一个内部类,注意它的属性都是定义为static final'''
private static class IntegerCache {
static final int high; '''//缓存上界,暂为null'''
static final Integer cache[]; '''//缓存的整型数组'''
'''// 块,为什么定义为块'''
static {
final int low = -128; '''// 缓存下界,不可变了。只有上界可以改变'''
'''// high value may be configured by property'''
'''// h值,可以通过设置jdk的AutoBoxCacheMax参数调整(以下有解释),自动缓存区间设置为[-128,N]。注意区间的下界是固定'''
int h = 127;
if (integerCacheHighPropValue != null) {
'''// Use Long.decode here to avoid invoking methods that'''
'''// require Integer's autoboxing cache to be initialized'''
// 通过解码integerCacheHighPropValue,而得到一个候选的上界值'''
int i = Long.decode(integerCacheHighPropValue).intValue();
'''// 取较大的作为上界,但又不能大于Integer的边界MAX_VALUE'''
i = Math.max(i, 127);
'''// Maximum array size is Integer.MAX_VALUE'''
h = Math.min(i, Integer.MAX_VALUE - -low);
}
high = h; '''//上界确定'''
'''// 就可以创建缓存块,注意缓存数组大小'''
cache = new Integer[(high - low) + 1]; //
int j = low;
for(int k = 0; k < cache.length; k++)
cache[k] = new Integer(j++); '''// -128到high值逐一分配到缓存数组'''
}
private IntegerCache() {}
}
public class Main{
public static void main(String[] args){
Double i1 = 100.0;
Double i2 = 100.0;
Double i3 = 200.0;
Double i4 = 200.0;
System.out.println(i1==i2);
System.out.println(i3==i4);
}
}
public static Boolean valueOf(boolean b) {
return (b ? TRUE : FALSE);
}
public static final Boolean TRUE = new Boolean(true); '''/** ''' '''* The <code>Boolean</code> object corresponding to the primitive ''' '''* value <code>false</code>. ''' '''*/''' public static final Boolean FALSE = new Boolean(false);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有