具体看如下代码
public class AutoBox {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer i = 13;
Integer j = 13;
Integer i1 = 137;
Integer j1 = 137;
System.out.println(i == j );//true
System.out.println(i1 == j1 );//false
}
}
在java中 如果用到1字节以内的数字 它会把他缓存起来进行复用
public class AutoBox {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Integer i = 13;
Integer j = 13;
Integer i1 = 137;
Integer j1 = 137;
System.out.println(i == j );//true
System.out.println(i1 == j1 );//false
}
}
在java中 如果用到1字节以内的数字 它会把他缓存起来进行复用
本文通过一个Java示例代码介绍了自动装箱的概念,并展示了在特定数值范围内Integer对象的比较结果。揭示了Java为提高效率对于-128至127之间的整数会进行缓存复用的细节。

被折叠的 条评论
为什么被折叠?



