Skip to Content
Java in a Nutshell, 5th Edition
book

Java in a Nutshell, 5th Edition

by David Flanagan
March 2005
Intermediate to advanced
1254 pages
104h 21m
English
O'Reilly Media, Inc.
Content preview from Java in a Nutshell, 5th Edition

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( )}

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java in a Nutshell, 8th Edition

Java in a Nutshell, 8th Edition

Benjamin J. Evans, Jason Clark, David Flanagan
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan
Learning Java, 5th Edition

Learning Java, 5th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 0596007736Supplemental ContentErrata Page