Basic types of caching resolver
Integer caching resolver
1 |
private static class { |
1, the use of automatic packing (Integer i = 1) way to create an Integer object, use valueOf be Integer object initialization, this time, will call IntegerCache.high, which is required for IntegerCache This static inner classes to initialize.
2, IntegerCache class has a cache array, when the loading IntegerCache, Integer object will be -128 to 127 are created and store into the cache array, and then determining whether the current value of the Integer object initialized to -128 between 127, and if so, taken directly from the cache buffer, and if not, the new a new Integer object.
3, after the re-create the Integer object using automatic packing way, values taken directly from the cache when the cache between -128 to 127.
Therefore, Integer object created using an automatic packing way, when the two compared values are equal so long as it is ture. Not between -128 to 127, when compared will a new object is new, resulting in the comparison result is false
Note : The minimum value Integer is fixed, only -128 and the highest value can be set via jvm parameters. In the implementation of java program plus -XX: AutoBoxCacheMax =
Long and Byte, Character caching resolver
1 |
private static class LongCache { |
Similarly Long caching mechanism (LongCache) and Integer, as well as Character (CharacterCache), Byte (ByteCache) caching mechanism is similar. However, only a maximum of Integer jvm parameters can be set, the others are fixed. Wherein, Byte, Short, Long range: -128 to 127; Character, the range is 0 to 127.
Follow me on micro-channel public number: FramePower
I occasionally releases related technology accumulation, welcomed the technical pursuit, like-minded friends to join and learn to grow together!
Original: Big Box Java foundation - Data type caching resolver