SoftReference: get() : SoftReference « java.lang.ref « Java by API






SoftReference: get()

  

import java.lang.ref.SoftReference;

public class Main {
  public static void 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");
    }
  }
}

   
    
  








Related examples in the same category

1.new SoftReference(String referent)
2.new SoftReference(Object object, ReferenceQueue r)