Java SE API
ReferenceQueue.poll
Return the next queued reference or null without blocking.
Formal Syntax & Structure
java syntaxjava
queue.poll()Working Example
Example Snippetjava
public class Main {
public static void main(String[] args) throws Exception { var queue = new java.lang.ref.ReferenceQueue<Object>(); Object value = new Object(); var ref = new java.lang.ref.WeakReference<>(value, queue); System.out.println(queue.poll() == null); System.out.println(ref.enqueue()); System.out.println(queue.poll() == ref); java.lang.ref.Reference.reachabilityFence(value); }}