Referencepublic abstract class Reference extends Object Provides an abstract class which describes behavior common to all reference
objects. It is not possible to create immediate subclasses of
{@code Reference} in addition to the ones provided by this package. It is
also not desirable to do so, since references require very close cooperation
with the system's garbage collector. The existing, specialized reference
classes should be used instead. |
Fields Summary |
---|
T | referentThe object to which this reference refers.
VM requirement: this field must be called "referent"
and be an object. | ReferenceQueue | queueIf non-null, the queue on which this reference will be enqueued
when the referent is appropriately reachable.
VM requirement: this field must be called "queue"
and be a java.lang.ref.ReferenceQueue. | Reference | queueNextUsed internally by java.lang.ref.ReferenceQueue.
VM requirement: this field must be called "queueNext"
and be a java.lang.ref.Reference. | private int | vmDataUsed internally by Dalvik.
VM requirement: this field must be called "vmData"
and be an int. |
Constructors Summary |
---|
Reference()Constructs a new instance of this class.
super();
|
Methods Summary |
---|
public void | clear()Makes the referent {@code null}. This does not force the reference
object to be enqueued.
referent = null;
| public boolean | enqueue()Forces the reference object to be enqueued if it has been associated with
a queue.
return enqueueInternal();
| private synchronized boolean | enqueueInternal()An implementation of .enqueue() that is safe for the VM to call.
If a Reference object is a subclass of any of the
java.lang.ref.*Reference classes and that subclass overrides enqueue(),
the VM may not call the overridden method.
VM requirement: this method must be called "enqueueInternal",
have the signature "()Z", and be private.
/* VM requirement:
* The VM assumes that this function only does work
* if "(queue != null && queueNext == null)".
* If that changes, Dalvik needs to change, too.
* (see MarkSweep.c:enqueueReference())
*/
if (queue != null && queueNext == null) {
queue.enqueue(this);
queue = null;
return true;
}
return false;
| public T | get()Returns the referent of the reference object.
return referent;
| public boolean | isEnqueued()Checks whether the reference object has been enqueued.
return queueNext != null;
|
|