mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-16 18:10:13 +08:00
Update java-basic-questions-01.md
`Integer i1=40` 这一行代码会发生拆箱
This commit is contained in:
parent
3684aac82c
commit
1f89e164ba
@ -509,7 +509,7 @@ Integer i2 = new Integer(40);
|
||||
System.out.println(i1==i2);
|
||||
```
|
||||
|
||||
`Integer i1=40` 这一行代码会发生拆箱,也就是说这行代码等价于 `Integer i1=Integer.valueOf(40)` 。因此,`i1` 直接使用的是缓存中的对象。而`Integer i2 = new Integer(40)` 会直接创建新的对象。
|
||||
`Integer i1=40` 这一行代码会发生装箱,也就是说这行代码等价于 `Integer i1=Integer.valueOf(40)` 。因此,`i1` 直接使用的是缓存中的对象。而`Integer i2 = new Integer(40)` 会直接创建新的对象。
|
||||
|
||||
因此,答案是 `false` 。你答对了吗?
|
||||
|
||||
@ -1023,4 +1023,4 @@ public class VariableLengthArgument {
|
||||
- Differences between Oracle JDK and OpenJDK:https://stackoverflow.com/questions/22358071/differences-between-oracle-jdk-and-openjdk
|
||||
- 彻底弄懂 Java 的移位操作符:https://juejin.cn/post/6844904025880526861
|
||||
|
||||
<!-- @include: @article-footer.snippet.md -->
|
||||
<!-- @include: @article-footer.snippet.md -->
|
||||
|
Loading…
x
Reference in New Issue
Block a user