例3.10.5-1.Java语言规范8的字符串文字告诉我们:
该程序由编译单元组成(第7.3节):
package testPackage;
class Test {
public static void main(String[] args) {
String hello = "Hello", lo = "lo";
System.out.print((hello == "Hello") + " ");
System.out.print((Other.hello == hello) + " ");
System.out.print((other.Other.hello == hello) + " ");
System.out.print((hello == ("Hel"+"lo")) + " ");
System.out.print((hello == ("Hel"+lo)) + " ");
System.out.println(hello == ("Hel"+lo).intern());
}
}
class Other { static String hello = "Hello"; }
Run Code Online (Sandbox Code Playgroud)
和编译单位:
package other;
public class Other { public static String hello = …Run Code Online (Sandbox Code Playgroud) java ×1