实例:
//缓存
Integer in1 = -128;
Integer in2 = -128;
System.out.println(in1 == in2);
System.out.println(in1.equals(in2));
运行结果为true true
分析:
进入Integer.valueOf源码
![缓存[-128-127]数字](https://www.7z7z7z.cn/wp-content/uploads/2020/06/image.png)
首先,会看到进行了一个缓存最小和最大值的一个判断,在此范围内直接返回对应cache数组,再查看low和high的值
![缓存[-128-127]数字](https://www.7z7z7z.cn/wp-content/uploads/2020/06/image-1.png)
low值为-128,high值为127,还有一个cache缓存的数组
![缓存[-128-127]数字](https://www.7z7z7z.cn/wp-content/uploads/2020/06/image-2.png)
在启动是便生成Integer对象,并把对象放入cache数组
结论:
包装类-128-127之间为cache数组内对象,不在此范围内则new新对象






