A soft reference holds onto its referent until memory becomes low.
import java.lang.ref.SoftReference;
publicclass Main {
publicstaticvoid main(String[] argv) throws Exception {
SoftReference<String> sr = new SoftReference<String>("object");
Object o = sr.get();
if (o != null) {
System.out.println(o);
} else {
System.out.println("collected or has been reclaimed");
}
}
}