java.lang.ref

Class 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
Tget()
Returns the object, this reference refers to.

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.

Returns: null, since the refered object may be finalized and thus not accessible.