mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-16 18:10:13 +08:00
修改文章中装箱写成拆箱的笔误
This commit is contained in:
parent
07cc257b74
commit
b51b8269f5
@ -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()` 方法比较**。
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user