Code example for SoftReference

0
 
  public T getValue() { 
    T t;
    if (myReference == null || (t = myReference.get()) == null) {
      t = compute();
      myReference = new SoftReference<T>(t);
    } 
    return t;
  } 
 
  @NotNull 
  protected abstract T compute(); 
}