Testing WeakReference
问题 What is the proper approach to testing a weak reference in Java? My initial idea is to do the following: public class WeakReferenceTest { public class Target{ private String value; public Target(String value){ this.value = value; } public String toString(){ return value; } } public class UsesWeakReference{ WeakReference<Target> reference; public UsesWeakReference(Target test){ reference = new WeakReference<Target>(test); } public String call(){ Target test = reference.get(); if(test != null){