Skip to content

Commit 55cb730

Browse files
committed
Update Java内存区域.md
1 parent 0abe6e1 commit 55cb730

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

docs/java/jvm/Java内存区域.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,10 @@ String s1 = "计算机";
354354
String s2 = s1.intern();
355355
String s3 = "计算机";
356356
System.out.println(s2);//计算机
357-
System.out.println(s1.equals(s2));//true
358-
System.out.println(s3.equals(s2));//true,因为两个都是常量池中的 String 对象
357+
System.out.println(s1 == s2);//true
358+
System.out.println(s3 == s2);//true,因为两个都是常量池中的 String 对象
359359
```
360360
361-
`s1.equals(s2)` 输出为 true 的原因 :
362-
363-
1. s1 调用 `intern()` 的时候,因为常量池没有对应的字面量,所以在常量池保存了一个指向 s1 的引用
364-
2. 接下来的 s2 会先去常量池里找,找到对应引用,故指向堆里的 s1
365-
3.`s1.equals(s2)` 为 true
366-
367361
**字符串拼接:**
368362
369363
```java

0 commit comments

Comments
 (0)