5*6* The cache is initialized on first usage. The size of the cache7* may be controlled by the {@code-XX:AutoBoxCacheMax=} option.8* During VM initialization, java.lang.Integer.IntegerCache.high property9* may be set and saved in the private system properties in the10* sun.misc.VM ...
127);// Maximum array size is Integer.MAX_VALUEh=Math.min(h,Integer.MAX_VALUE-(-low)-1);}catch(NumberFormatExceptionnfe){// If the property cannot be parsed into an int, ignore it.}}high=h;// Load IntegerCache.archivedCache from archive, if possibleCDS.initializeFromArchive(IntegerCac...
* The cache is initialized on first usage. The size of the cache * may be controlled by the {@code -XX:AutoBoxCacheMax=} option. * During VM initialization, java.lang.Integer.IntegerCache.high property * may be set and saved in the private system properties in the * sun.misc.VM class...
This method will always cache values in the range -128 to 127, inclusive, and may cache other values outside of this range. Parameters: i - an int value. Returns: an Integer instance representing i. Since: 1.5 byteValue public byte byteValue() Returns the value of this Integer as a ...
Java的Integer类有一个内部的缓存机制,主要用于优化自动装箱(autoboxing)和拆箱(unboxing)的性能。这个特性首次引入于Java 5,旨在减少对频繁使用的小整数值的重复对象创建,从而提高性能和减少内存使用。 参数文档:Java Integer包装类缓存(cache)-CJavaPy 1、缓存范围 ...
在创建新的 Integer 对象之前会先在 IntegerCache.cache 中查找。有一个专门的 Java 类来负责 Integer 的缓存。 IntegerCache 类 IntegerCache 是 Integer 类中一个私有的静态类。我们来看看这个类,有比较详细的文档,可以提供我们很多信息 /** * Cache to support the object identity semantics of autoboxing for ...
static final Integer[] cache; static Integer[] archivedCache; static { // high value may be configured by property int h = 127; String integerCacheHighPropValue = VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); if (integerCacheHighPropValue != null) { ...
此方法是获取 VM参数中的AutoBoxCacheMax的值 public class IntegerCacheExample { public static void main(String[] args) { System.out.printf("high:%s.\n", sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high")); Integer a = 127; Integer b = 127; System.out.printf("a==b: ...
* The cache is initialized on first usage. The size of the cache * may be controlled by the -XX:AutoBoxCacheMax=<size> option. * During VM initialization, java.lang.Integer.IntegerCache.high property * may be set and saved in the private system properties in the ...
cache[i + (-IntegerCache.low)]; return new Integer(i); } 通过源码可以看出,如果用 Ineger.valueOf(int) 来创建整数对象,参数大于等于整数缓存的最小值( IntegerCache.low )并小于等于整数缓存的最大值( IntegerCache.high), 会直接从缓存数组 (java.lang.Integer.IntegerCache#cache) 中提取整数对象;否则...