首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

关于java中的部类比较面试题,求解

2012-08-29 
关于java中的类型比较面试题,求解?1. public static Integer valueOf(int i) {assert IntegerCache.high

关于java中的类型比较面试题,求解?

1.

public static Integer valueOf(int i) {assert IntegerCache.high >= 127;if (i >= IntegerCache.low && i <= IntegerCache.high)return IntegerCache.cache[i + (-IntegerCache.low)];return new Integer(i);}...private static class IntegerCache {static final int low = -128;static final int high;static final Integer cache[];static {// high value may be configured by propertyint h = 127;String integerCacheHighPropValue =sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");if (integerCacheHighPropValue != null) {int i = parseInt(integerCacheHighPropValue);i = Math.max(i, 127);// Maximum array size is Integer.MAX_VALUEh = 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++);}private IntegerCache() {}}

至于情况(1),可能为true,也可能为false,java要求-128到127必须缓存,所以在这个范围内的情况(1)一定为true,超出这个范围的看具体实现和参数,jdk7就有参数可以调整这个缓存的大小。 9 楼 ps329795485 2012-03-03   以前面试也有遇到这问题

热点排行