package java.lang.ref; public abstract class ReferenceQueue { private Reference front; private Reference rear; public Reference poll() { Reference r = front; if (front != null) { if (front == front.next) { front = rear = null; } else { front = front.next; } } return r; } void add(Reference r) { r.next = r; if (front == null) { front = rear = r; } else { rear.next = r; rear = r; } } }