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

修改文章中装箱写成拆箱的笔误

This commit is contained in:
VinterHe 2021-06-04 17:17:03 +08:00 committed by GitHub
parent 07cc257b74
commit b51b8269f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,7 +77,7 @@ Integer i2 = new Integer(40);
System.out.println(i1==i2);//false
```
`Integer i1=40` 这一行代码会发生箱,也就是说这行代码等价于 `Integer i1=Integer.valueOf(40)` 。因此,`i1` 直接使用的是常量池中的对象。而`Integer i1 = new Integer(40)` 会直接创建新的对象。因此,输出 false 。
`Integer i1=40` 这一行代码会发生箱,也就是说这行代码等价于 `Integer i1=Integer.valueOf(40)` 。因此,`i1` 直接使用的是常量池中的对象。而`Integer i1 = new Integer(40)` 会直接创建新的对象。因此,输出 false 。
记住:**所有整型包装类对象之间值的比较,全部使用 `equals()` 方法比较**。