File tree Expand file tree Collapse file tree 1 file changed +2
-1
lines changed Expand file tree Collapse file tree 1 file changed +2
-1
lines changed Original file line number Diff line number Diff line change @@ -294,7 +294,7 @@ System.out.println(str2==str3);//false
294294** String 类型的常量池比较特殊。它的主要使用方法有两种:**
295295
296296- 直接使用双引号声明出来的 String 对象会直接存储在常量池中。
297- - 如果不是用双引号声明的 String 对象,可以使用 String 提供的 intern 方法。String.intern() 是一个 Native 方法,它的作用是:如果运行时常量池中已经包含一个等于此 String 对象内容的字符串,则返回常量池中该字符串的引用;如果没有,则在常量池中创建与此 String 内容相同的字符串,并返回常量池中创建的字符串的引用。
297+ - 如果不是用双引号声明的 String 对象,可以使用 String 提供的 intern 方法。String.intern() 是一个 Native 方法,它的作用是:如果运行时常量池中已经包含一个等于此 String 对象内容的字符串,则返回常量池中该字符串的引用;如果没有,JDK1.7之前(不包含1.7)的处理方式是在常量池中创建与此 String 内容相同的字符串,并返回常量池中创建的字符串的引用,JDK1.7以及之后的处理方式是在常量池中记录此字符串的引用,并返回该引用 。
298298
299299``` java
300300 String s1 = new String (" 计算机" );
@@ -421,6 +421,7 @@ i4=i5+i6 true
421421- < http://www.pointsoftware.ch/en/under-the-hood-runtime-data-areas-javas-memory-model/ >
422422- < https://dzone.com/articles/jvm-permgen-%E2%80%93-where-art-thou >
423423- < https://stackoverflow.com/questions/9095748/method-area-and-permgen >
424+ - 深入解析String#intern< https://tech.meituan.com/2014/03/06/in-depth-understanding-string-intern.html >
424425
425426## 公众号
426427
You can’t perform that action at this time.
0 commit comments