Integer源码分析

在这里插入图片描述
Integer简述
Integer是JDK1.5出现的int原生类型的包装类型,在JDK9之前版本,通常是使用构造函数的方式创建对象:

Integer integer = new Integer(1);
从JDK9开始之后,通过构造方法这种方式创建Integer对象的方式被抛弃,使用Integer提供的静态方法来创建对象:

Integer integer = Integer.valueOf(1);
Integer为用户创建integer对象提供了基于int和String的两种类型的方式:

下面主要讨论的基于jdk11的源码进行分析。

Integer基本属性
//Integer可以装箱的int最小值,采用16进制表示
@Native public static final int MIN_VALUE = 0x80000000;
//Integer可以装箱的int最大值
@Native public static final int MAX_VALUE = 0x7fffffff;
//实际保存原生int的值
private final int value;
//表示的Integer所表示的int类型占32位
@Native public static final int SIZE = 32;
//表示int的字节数
public static final int BYTES = SIZE / Byte.SIZE;
//所有的数子和字母字符
static final char[] digits = {
‘0’ , ‘1’ , ‘2’ , ‘3’ , ‘4’ , ‘5’ ,
‘6’ , ‘7’ , ‘8’ , ‘9’ , ‘a’ , ‘b’ ,
‘c’ , ‘d’ , ‘e’ , ‘f’ , ‘g’ , ‘h’ ,
‘i’ , ‘j’ , ‘k’ , ‘l’ , ‘m’ , ‘n’ ,
‘o’ , ‘p’ , ‘q’ , ‘r’ , ‘s’ , ‘t’ ,
‘u’ , ‘v’ , ‘w’ , ‘x’ , ‘y’ , ‘z’

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值