Module java.base
Package java.lang.ref

Class SoftReference<T>

java.lang.Object
java.lang.ref.Reference<T>
java.lang.ref.SoftReference<T>

public class SoftReference<T> extends Reference<T>
SoftReference objects are used to detect referents which are no longer visible and who's memory is to be reclaimed.
Since:
1.2
  • Constructor Details

    • SoftReference

      public SoftReference(T r, ReferenceQueue<? super T> q)
      Constructs a new instance of this class.
      Parameters:
      r - referent to track.
      q - queue to register to the reference object with.
    • SoftReference

      public SoftReference(T r)
      Constructs a new instance of this class.
      Parameters:
      r - referent to track.
  • Method Details

    • get

      public T get()
      Return the referent of the reference object.
      Overrides:
      get in class Reference<T>
      Returns:
      Referent to which reference refers, or null if object has been cleared.