String s = new String("hello") 创建了几个对象
两个。一个是 “hello”,一个是 new String("hello") 。
public static void main(String[] args) {
String s = "hello"; //常量池中创建 hello 对象
/**
* 如果常量池中已经有 "hello"了,则创建一个对象 new String("hello"),在堆中。
* 否则就创建两个,一个是"hello",一个是 new String("hello")
*/
String s1 = new String("hello");
/**
* 如果多个字符串 + ,也是类似的逻辑。
* 如果常量池中有,那么就用常量池中的。否则就创建新的
*/
}