Class WeakReference<T,​A>

  • Type Parameters:
    T - the reference value type
    A - the attachment type
    All Implemented Interfaces:
    Reapable<T,​A>, Reference<T,​A>

    public class WeakReference<T,​A>
    extends java.lang.ref.WeakReference<T>
    implements Reference<T,​A>, Reapable<T,​A>
    A reapable weak reference with an attachment. If a Reaper is given, then it will be used to asynchronously clean up the referent.
    See Also:
    WeakReference
    • Field Detail

      • attachment

        private final A attachment
      • reaper

        private final Reaper<T,​A> reaper
    • Constructor Detail

      • WeakReference

        public WeakReference​(T referent)
      • WeakReference

        public WeakReference​(T referent,
                             A attachment)
      • WeakReference

        public WeakReference​(T referent,
                             A attachment,
                             java.lang.ref.ReferenceQueue<? super T> q)
      • WeakReference

        public WeakReference​(T referent,
                             A attachment,
                             Reaper<T,​A> reaper)
    • Method Detail

      • getAttachment

        public A getAttachment()
        Description copied from interface: Reference
        Get the attachment, if any.
        Specified by:
        getAttachment in interface Reference<T,​A>
        Returns:
        the attachment
      • getReaper

        public Reaper<T,​A> getReaper()
        Description copied from interface: Reapable
        Get the associated reaper.
        Specified by:
        getReaper in interface Reapable<T,​A>
        Returns:
        the reaper
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object