java.lang.ref
Class PhantomReference<T>

java.lang.Object
  extended by java.lang.ref.Reference<T>
      extended by java.lang.ref.PhantomReference<T>

public class PhantomReference<T>
extends Reference<T>

A phantom reference is useful, to get notified, when an object got finalized. You can't access that object though, since it is finalized. This is the reason, why get() always returns null.


Constructor Summary
PhantomReference(T referent, ReferenceQueue<? super T> q)
          Creates a new phantom reference.
 
Method Summary
 T get()
          Returns the object, this reference refers to.
 
Methods inherited from class java.lang.ref.Reference
clear, enqueue, isEnqueued
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PhantomReference

public PhantomReference(T referent,
                        ReferenceQueue<? super T> q)
Creates a new phantom reference.

Parameters:
referent - the object that should be watched.
q - the queue that should be notified, if the referent was finalized. This mustn't be null.
Throws:
NullPointerException - if q is null.
Method Detail

get

public T get()
Returns the object, this reference refers to.

Overrides:
get in class Reference<T>
Returns:
null, since the refered object may be finalized and thus not accessible.