字符串常量池也是运行时常量池 jdk1.6中,它是在方法区中,属于“永久代” jdk1.7中,它被移除方法区,放在java堆中 jdk1.8中,取消了“永久代”,将常量池放在元空间,与堆独立了 public class RuntimeConstantPoolOOM { public static void main(String[] args) throws Exception{ String str1 = new StringBuffer("计算机").append("sh
https://www.jianshu.com/p/af6eb8d3d4bf 首先看一段程序: using System; class Program { static void Main(string[] args) { string a = "hello world"; string b = a; a = "hello"; Console.WriteLine("{0}, {1}", a, b); Console.WriteLine(a ==
引言 什么都先不说,先看下面这个引入的例子: public static void test4(){ String str1 = new String("SEU") + new String("Calvin"); System.out.println(str1.intern() == str1); System.out.println(str1 == "SEUCalvin"); } 再将上面的例子加上一行代码: public static voi
参考:https://www.jianshu.com/p/0d1c003d2ff5 String.intern() String.intern()是native方法,底层调用c++中的StringTable:intern方法. 当调用intern方法是,如果常量池已经存在该字符串,则返回池中字符串. 否则将此字符串添加到常量池中,并返回字符串的引用. package com.ctrip.ttd.whywhy; class Test { public static void main(String