Name

Reference<T>

Synopsis

This abstract class represents some type of indirect reference to a referent. get( ) returns the referent if the reference has not been explicitly cleared by the clear( ) method or implicitly cleared by the garbage collector. There are three concrete subclasses of Reference. The garbage collector handles these subclasses differently and clears their references under different circumstances.

Each of the subclasses of Reference defines a constructor that allows a ReferenceQueue to be associated with the Reference object. The garbage collector places Reference objects onto their associated ReferenceQueue objects to provide notification about the state of the referent object. isEnqueued( ) tests whether a Reference has been placed on the associated queue, and enqueue( ) explicitly places it on the queue. enqueue( ) returns false if the Reference object does not have an associated ReferenceQueue, or if it has already been enqueued.

public abstract class Reference<T> {
// No Constructor
                  // Public Instance Methods
     public void clear( );  
     public boolean enqueue( );  
     public T get( );  
     public boolean isEnqueued( );  
}

Subclasses

PhantomReference, SoftReference, WeakReference

Returned By

ReferenceQueue.{poll( ), remove( )}

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.