当我在 wikipedia http://en.wikipedia.org/wiki/Weak_reference上阅读以下示例代码时
import java.lang.ref.WeakReference;
public class ReferenceTest {
public static void main(String[] args) throws InterruptedException {
WeakReference r = new WeakReference(new String("I'm here"));
WeakReference sr = new WeakReference("I'm here");
System.out.println("before gc: r=" + r.get() + ", static=" + sr.get());
System.gc();
Thread.sleep(100);
// only r.get() becomes null
System.out.println("after gc: r=" + r.get() + ", static=" + sr.get());
}
}
gc 之前的输出 :r=我在这里,static=我在这里 gc 之后:r=null,static=我在这里
我无法理解 gc 之后的输出,sr(WeakReference) 对字符串池中字符串的强引用在哪里