【发布时间】:2014-05-22 07:52:06
【问题描述】:
我对String的intern方法不太了解。
String s1="java"; // should create one object in String Constant pool
String ss="java"; // no object is created (java is already in String pool)..it refers to object in String constant pool
String s2= new String("Android").intern(); // should create 2 objects one in heap and second in String constant pool
String s3= new String("java").intern()// i guess only one object is created on heap and s3 will point to object in String constant pool (as 'java' already exist).so the object in heap is lost because there is no reference
请告诉我我的理解是否正确?
【问题讨论】:
-
我认为这是对
String pool这个想法的正确理解。 -
所以我的所有假设都是正确的?
-
对
new String的使用感慨