1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Update Java疑难点.md

This commit is contained in:
SnailClimb 2019-07-17 17:20:17 +08:00
parent 15635fdffa
commit 10ae230a61

View File

@ -78,7 +78,7 @@ System.out.println(x == y);// true
Integer a = new Integer(3);
Integer b = new Integer(3);
System.out.println(a == b);//false
System.out.println(a.equals(b));//false
System.out.println(a.equals(b));//true
```
当使用自动装箱方式创建一个Integer对象时当数值在-128 ~127时会将创建的 Integer 对象缓存起来当下次再出现该数值时直接从缓存中取出对应的Integer对象。所以上述代码中x和y引用的是相同的Integer对象。