class A {
String s = "abc";
}
class B {
String s = "abc";
static public void main(String[]args ) {
A a = new A();
B b = new B();
System.out.println("a.s==b.s : " + (a.s==b.s));
}
}
产出:
a.s==b.s : true
If the literal is written to the "constant pool" part of the classfile,how come 2 literals(the same contents) in 2 classes use the same interned string? How does the compiler link them together?