博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java | JDK8 | Integer
阅读量:4594 次
发布时间:2019-06-09

本文共 1949 字,大约阅读时间需要 6 分钟。

Integer 继承 抽象类Number和实现 Comparable<Integer>接口,

抽象类Number:提供拆箱的超类,可转换的基本类型有 {@code byte}, {@code double}, {@code float}, {@code int}, {@code long}, and {@code short}.

Comparable<Integer>接口:提供Integer类实现自身比较。

 

Integer类的最大值最小值

@Native public static final int   MIN_VALUE = 0x80000000;@Native public static final int   MAX_VALUE = 0x7fffffff;

最小值 -2^31,最大值2^31

 

Integer类的缓存

  Integer的缓存值从-127开始,默认是到127,在static静态代码块进行初始化,在源码中可以看出缓存值的上限high是可以设置

static final int low = -128;static final int high;static final Integer cache[]; static {     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;}public static Integer valueOf(int i) {        if (i >= IntegerCache.low && i <= IntegerCache.high)            return IntegerCache.cache[i + (-IntegerCache.low)];        return new Integer(i); }

 

Integer类与int自动拆箱与装箱

//拆箱 public int intValue() {        return value;  }//装箱public static Integer valueOf(int i) {        if (i >= IntegerCache.low && i <= IntegerCache.high)            return IntegerCache.cache[i + (-IntegerCache.low)];        return new Integer(i); }

 

转载于:https://www.cnblogs.com/jj81/p/11509299.html

你可能感兴趣的文章
20145205 《Java程序设计》实验报告三:敏捷开发与XP实践
查看>>
利用Spring.NET实现WCF的AOP编程
查看>>
第三方,解决模型无法在获取网络数据之后传值问题
查看>>
对比 Git 与 SVN,这篇讲的很易懂
查看>>
【snmp】Linux开启snmp及查询
查看>>
CSU 1532: JuQueen(线段树)
查看>>
设定MyEclipse编辑代码区域文字的大小及非keyword的字体、字形和颜色
查看>>
LeetCode【6】. ZigZag Conversion --思路图解与java实现
查看>>
git 合并分支
查看>>
NSNotification与NSNotificationCenter
查看>>
qt 中文乱码 处理QByteArray类型里含中文的数据
查看>>
跨库事务一致性问题的解决方式(例)
查看>>
ios build时,Undefined symbols for architecture xxx问题的总结
查看>>
JavaScript对象
查看>>
南理第八届校赛同步赛-C count_prime//容斥原理
查看>>
CentOS7.4下使用Nginx配置Asp.net Core和添加Https证书步骤
查看>>
常用模块介绍
查看>>
一台云服务器怎么同时响应多个域名?
查看>>
【黑客免杀攻防】读书笔记1 - 初级免杀基础理论(反病毒软件特征码提取介绍、免杀原理、壳)...
查看>>
Java 枚举类
查看>>