What is the difference between jdk8 and jdk17 in StringTable?

65 Views Asked by At

when I run this program in jdk8 and jdk17, the result is different.

    public class StringIntern {
    public static void main(String[] args) {

        String s = new String("1");
        s.intern();
        String s2 = "1";
        System.out.println(s == s2);//jdk6:false   jdk7/8:false

       
        String s3 = new String("1") + new String("1");//pos_1
        s3.intern();

        String s4 = "11";
        System.out.println(s3 == s4);//jdk6:false  jdk7/8:true


    }
}

JDK8: false true

JDK17: false false

Can you tell me why? Thanks a lot.

0

There are 0 best solutions below