< prev index next >

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

Print this page

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




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

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