首页 > 其他分享 >Code Gets New

Code Gets New

时间:2022-09-19 11:37:27浏览次数:54  
标签:Code int high static low Integer New Gets IntegerCache

JDK

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() {}
    }

标签:Code,int,high,static,low,Integer,New,Gets,IntegerCache
From: https://www.cnblogs.com/60kmph/p/16707135.html

相关文章

  • vscode 花括号 突出连接线 bracket 两个设置点
    vscode花括号突出连接线bracket两个设置点外观设置设置里面搜索bracketEditor-Guides:HighlightActiveBracketPairEditor-Guides:BracketPairs......
  • vscode设置背景图片
    参考:https://blog.csdn.net/lm1022/article/details/121609419file-perferences-settings-extensions-pluginbackgroundconfig-style-editinsettings.json改成下面这......
  • #100daysofcode
    #100daysofcodeR1D3问题在html中创建样式元素是否意味着我现在正在输入CSS?<style>元素{适当的价值;</style><style>h1{文本对齐:居中;</......
  • LeetCode链表翻转
    SwapNodesinPairsLeetCode/力扣递归交换之后,直接交换下一个节点ListNode*swapPairs(ListNode*head){if(head&&head->next){swap(head->val,......
  • LeetCode深度优先搜索
    ValidateBinarySearchTreeLeetCode/力扣递归boolisValidBST(TreeNode*root){doublelower=DBL_MIN;doubleupper=DBL_MAX;returnhelper(root......
  • LeetCode广度优先搜索
    BinaryTreeLevelOrderTraversalLeetCode/力扣递归voidlevelOrderHelper(vector<vector<int>>&res,intlevel,TreeNode*root){if(root==NULL)return;......
  • vscode 切换项目快捷键 Alt + Shift + P 插件 Project Manager
    vscode切换项目快捷键Alt+Shift+P插件ProjectManager需求快速切换同时打开的项目解决方案Alt+Shift+P话说这个插件很早就用了,但是由于每次需要左......
  • Leetcode solution 2353. Design a Food Rating System
     ProblemStatement Designafoodratingsystemthatcandothefollowing:Modify theratingofafooditemlistedinthesystem.Returnthehighest-rated......
  • LayaBox2.4配置VsCode编译及运行环境
    前言Laya2.4取消了内置VsCode编辑器,现在代码编辑需要在单独的代码编辑器里面写,推荐使用VsCode。发现不少同学无法运行启动调试了。这篇博客就是讲述如何配置编译及调试环......
  • Codeforces Round #316 (Div. 2) D Tree Requests
    TreeRequests判断\(V_i\)的子树中,深度为\(h_i\)的结点上所带有的字符,能否组成一个回文串启发式合并维护所有深度上不同字符的数量,并且维护其奇数字符出现的次数如......