常量池的1.8测试
2019-04-08 本文已影响0人
JaJIng
1.8的String.intern()好像有些变化,但是感觉和1.76没啥不同,难道是常量池引用那里有什么特别处理?
public class ConstantPool {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
stest t=new stest();
t.run();
}
}
class stest {
private static final String s11="hello";
private static final String s22="world";
public static void run() {
String s1="hello";
String s0=new String("hello");
String s01=new String("hello");
String s2="world";
String s3="helloworld";
String s4=s11+s22;
String s5=s1+"world";
String s6=s5.intern();
String s7="hello"+new String("world");
System.out.println(s3==s4); //t
System.out.println(s1==s0); //f
System.out.println(s01==s0); //f
System.out.println(s3==s5); //f
System.out.println(s4==s5); //f
System.out.println(s4==s6); //t
System.out.println(s3==s7); //f
System.out.println(s4==s7); //f
System.out.println(s5==s7); //f
}
}