• Integer


     public static Integer valueOf(int i) {
            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 property
                int h = 127;
                String integerCacheHighPropValue =
                    sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high");
                if (integerCacheHighPropValue != null) {
                    try {
                        int i = parseInt(integerCacheHighPropValue);
                        i = Math.max(i, 127);
                        // Maximum array size is Integer.MAX_VALUE
                        h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
                    } catch( NumberFormatException nfe) {
                        // If the property cannot be parsed into an int, ignore it.
                    }
                }
                high = h;

                cache = new Integer[(high - low) + 1];
                int j = low;
                for(int k = 0; k < cache.length; k++)
                    cache[k] = new Integer(j++);

                // range [-128, 127] must be interned (JLS7 5.1.7)
                assert IntegerCache.high >= 127;
            }

            private IntegerCache() {}
        }

    源码如上,就是说int在-128到127(不一定,可配置)之间,就去IntegerCache[],取一个对应值的Integer对象,不在范围内就之间new Integer(i)

  • 相关阅读:
    03-树3 Tree Traversals Again
    Utuntu下Xshell使用+vi使用
    CSDN总结的面试中的十大算法
    EDM(邮件营销)
    腾讯CDC谈扁平化设计
    Graph Search图谱搜索
    LBS 与 GPS 定位之间的区别
    中间件的理解
    夏梦竹谈Hive vs. HBase的区别
    维基百科上—数据仓库、数据挖掘、OLAP三者之间的区别
  • 原文地址:https://www.cnblogs.com/ljjnbpy/p/9981262.html
Copyright © 2020-2023  润新知