Java Integer 中的常量池/缓存技术

本文探讨了Java中的Integer缓存机制,指出Integer在[-128, 127]范围内使用常量池,缓存的上界可通过参数调整但不能低于127。当调用Integer.ValueOf()或自动装箱时,若数值在缓存范围内则直接引用,否则会新建对象。缓存策略旨在提升效率并节省内存。" 55095626,5630617,Picasso深度解析:Android高效图片加载,"['Android开发', '图片处理', '缓存技术', 'Picasso框架']
摘要由CSDN通过智能技术生成

IntegerCache 源码如下


    /**
     * 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
     * jdk.internal.misc.VM class.
     */

    private static class IntegerCache {
   
        static final int low = -128;
        static final int high;
        static final Integer cache[];

        static {
   
            // high value may be configured by property
            int h = 127;
            String integerCacheHighPropValue =
                VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
            if (integerCacheHighPropValue != null) {
   
                try {
   
                    int i = parseInt(integerCacheHighPropValue);
                    i = Math
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值