私は文字列プールがどのように機能するかを知っています。それは言った:
void doSomething1(){
System.out.println("This string is now added to the string pool and will stay there even after this method returns");
}
void doSomething2(){
String msg = new String("This string is now added to the string pool and will stay there even after this method returns");
System.out.println(msg);
}
doSomething2
よりも優れていますdoSomething1
。一部の文字列はreused
. 私が見る問題は、ケース 1 にあります。文字列は、再度使用されなくても長期間スコープ内にとどまります。