2007-07-20 00:18:47 +00:00
|
|
|
package java.lang.ref;
|
|
|
|
|
|
|
|
public abstract class Reference<T> {
|
2007-07-21 17:50:26 +00:00
|
|
|
private Object vmNext;
|
2007-07-20 00:18:47 +00:00
|
|
|
private T target;
|
|
|
|
private ReferenceQueue<? super T> queue;
|
2007-07-20 03:18:25 +00:00
|
|
|
Reference next;
|
2007-07-20 00:18:47 +00:00
|
|
|
|
|
|
|
protected Reference(T target, ReferenceQueue<? super T> queue) {
|
|
|
|
this.target = target;
|
|
|
|
this.queue = queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public T get() {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clear() {
|
2007-07-20 03:18:25 +00:00
|
|
|
target = null;
|
2007-07-20 00:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEnqueued() {
|
|
|
|
return next != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean enqueue() {
|
|
|
|
if (queue != null) {
|
|
|
|
queue.add(this);
|
|
|
|
queue = null;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|