< prev index next >

src/java.base/share/classes/java/lang/ref/Reference.java

Print this page

481      * Throws {@link CloneNotSupportedException}. A {@code Reference} cannot be
482      * meaningfully cloned. Construct a new {@code Reference} instead.
483      *
484      * @return never returns normally
485      * @throws  CloneNotSupportedException always
486      *
487      * @since 11
488      */
489     @Override
490     protected Object clone() throws CloneNotSupportedException {
491         throw new CloneNotSupportedException();
492     }
493 
494     /* -- Constructors -- */
495 
496     Reference(T referent) {
497         this(referent, null);
498     }
499 
500     Reference(T referent, ReferenceQueue<? super T> queue) {






501         this.referent = referent;
502         this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
503     }
504 
505     /**
506      * Ensures that the object referenced by the given reference remains
507      * <a href="package-summary.html#reachability"><em>strongly reachable</em></a>,
508      * regardless of any prior actions of the program that might otherwise cause
509      * the object to become unreachable; thus, the referenced object is not
510      * reclaimable by garbage collection at least until after the invocation of
511      * this method.  Invocation of this method does not itself initiate garbage
512      * collection or finalization.
513      *
514      * <p> This method establishes an ordering for <em>strong reachability</em>
515      * with respect to garbage collection.  It controls relations that are
516      * otherwise only implicit in a program -- the reachability conditions
517      * triggering garbage collection.  This method is designed for use in
518      * uncommon situations of premature finalization where using
519      * {@code synchronized} blocks or methods, or using other synchronization
520      * facilities are not possible or do not provide the desired control.  This

481      * Throws {@link CloneNotSupportedException}. A {@code Reference} cannot be
482      * meaningfully cloned. Construct a new {@code Reference} instead.
483      *
484      * @return never returns normally
485      * @throws  CloneNotSupportedException always
486      *
487      * @since 11
488      */
489     @Override
490     protected Object clone() throws CloneNotSupportedException {
491         throw new CloneNotSupportedException();
492     }
493 
494     /* -- Constructors -- */
495 
496     Reference(T referent) {
497         this(referent, null);
498     }
499 
500     Reference(T referent, ReferenceQueue<? super T> queue) {
501         if (referent != null && referent.getClass().isValue()) {
502             Class<?> c = referent.getClass();
503             throw new IllegalArgumentException("cannot reference a " +
504                     (c.isPrimitiveClass() ? "primitive class " : "value class ") +
505                     c.getName());
506         }
507         this.referent = referent;
508         this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
509     }
510 
511     /**
512      * Ensures that the object referenced by the given reference remains
513      * <a href="package-summary.html#reachability"><em>strongly reachable</em></a>,
514      * regardless of any prior actions of the program that might otherwise cause
515      * the object to become unreachable; thus, the referenced object is not
516      * reclaimable by garbage collection at least until after the invocation of
517      * this method.  Invocation of this method does not itself initiate garbage
518      * collection or finalization.
519      *
520      * <p> This method establishes an ordering for <em>strong reachability</em>
521      * with respect to garbage collection.  It controls relations that are
522      * otherwise only implicit in a program -- the reachability conditions
523      * triggering garbage collection.  This method is designed for use in
524      * uncommon situations of premature finalization where using
525      * {@code synchronized} blocks or methods, or using other synchronization
526      * facilities are not possible or do not provide the desired control.  This
< prev index next >