魏亮 发表于 2012-11-10 16:07
那这个类运行的结果是true
class Test
{
Integer类型缓存了-128~~127这个范围的数字- //实例
- Integer i1 = -129;
- Integer j1 = -129;
- System.out.println("Integer1 " + (i1 == j1));
-
- Integer i2 = -128;
- Integer j2 = -128;
- System.out.println("Integer2 " + (i2 == j2));
-
- Integer i3 = 127;
- Integer j3 = 127;
- System.out.println("Integer3 " + (i3 == j3));
-
- Integer i4 = 128;
- Integer j4 = 128;
- System.out.println("Integer4 " + (i4 == j4));
- //结果
- Integer1 false
- Integer2 true
- Integer3 true
- Integer4 false
复制代码 |