Java Traps
String
Knowledge points
String Constant Pool
Code
public class StringTest {
public static void main(String []args) {
System.out.println("1" == "1");
System.out.println(new String("1") == "1");
System.out.println(get() == "1");
System.out.println(getV2() == "1");
System.out.println(new String("1").intern() == "1");
System.out.println(get().intern() == "1");
System.out.println(getV2().intern() == "1");
}
public static String get() {
return "1";
}
public static String getV2() {
return new String("1");
}
}