java.lang.ref
Class PhantomReference<T>
java.lang.Object
java.lang.ref.Reference<T>
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.
Method Summary |
T |
get()
Returns the object, this reference refers to. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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.
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.