String Literals

 

String Literals

package testPackage;
class Test {
    public static void main(String[] args) {
        String hello = "Hello", lo = "lo";
        System.out.println(hello == "Hello");
        System.out.println(Other.hello == hello);
        System.out.println(other.Other.hello == hello);
        System.out.println(hello == ("Hel"+"lo"));
        System.out.println(hello == ("Hel"+lo));
        System.out.println(hello == ("Hel"+lo).intern());
    }
}

 

produces the output:

true
true
true
true
false
true

 

参考:https://docs.oracle.com/javase/specs/jls/se17/html/jls-3.html#d5e1973

##########################

posted @ 2022-03-16 20:34  西北逍遥  阅读(62)  评论(0编辑  收藏  举报