
1.概述
我们都知道 java Integer是有缓存的,缓存范围是 -128~127。但是这个值是一定的吗?
不一定。看源码。缓存大小居然可以改变
/**
* Cache to support the object identity semantics of autoboxing for values between
* -128 and 127 (inclusive) as required by JLS.
*
* The cache is initialized on first usage. The size of the cache
* may be controlled by the {@code -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
* sun.misc.VM class.
*/
本文探讨了Java Integer的缓存特性,指出缓存范围并非固定为-128到127,而是可以通过源码查看其可变性。在实际案例中,观察到132的缓存值从4变为5,引发对Integer缓存行为的深入思考。
订阅专栏 解锁全文

1088

被折叠的 条评论
为什么被折叠?



