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
##########################
QQ 3087438119