< prev index next > src/java.base/share/classes/java/lang/ref/Reference.java
Print this page
import jdk.internal.vm.annotation.IntrinsicCandidate;
import jdk.internal.access.JavaLangRefAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.ref.Cleaner;
+ import java.util.Objects;
+
/**
* Abstract base class for reference objects. This class defines the
* operations common to all reference objects. Because reference objects are
* implemented in close cooperation with the garbage collector, this class may
* not be subclassed directly.
+ * <p>
+ * The referent must be an {@linkplain Objects#hasIdentity(Object) identity object}.
+ * Attempts to create a reference to a value object result in an {@link IdentityException}.
* @param <T> the type of the referent
*
* @author Mark Reinhold
* @since 1.2
* @sealedGraph
Reference(T referent) {
this(referent, null);
}
Reference(T referent, ReferenceQueue<? super T> queue) {
+ if (referent != null) {
+ Objects.requireIdentity(referent);
+ }
this.referent = referent;
this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
}
/**
< prev index next >