zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    hdu5608 function
    Codeforces Round #535 (Div. 3) 解题报告
    HDU4746 Mophues
    HDU5663 Hillan and the girl
    AtCoder Beginner Contest 117 解题报告
    GDOI2018D2T1 谈笑风生
    BZOJ4018: 小Q的幻想之乡
    牛客寒假算法基础集训营6 解题报告
    win32拖拽编程
    项目开发中的贝塞尔曲线
  • 原文地址:https://www.cnblogs.com/ljjnbpy/p/9981262.html
Copyright © 2011-2022 走看看