src/share/classes/java/lang/ref/SoftReference.java

Print this page
rev 905 : imported patch ref


  91      * @param referent object the new soft reference will refer to
  92      * @param q the queue with which the reference is to be registered,
  93      *          or <tt>null</tt> if registration is not required
  94      *
  95      */
  96     public SoftReference(T referent, ReferenceQueue<? super T> q) {
  97         super(referent, q);
  98         this.timestamp = clock;
  99     }
 100 
 101     /**
 102      * Returns this reference object's referent.  If this reference object has
 103      * been cleared, either by the program or by the garbage collector, then
 104      * this method returns <code>null</code>.
 105      *
 106      * @return   The object to which this reference refers, or
 107      *           <code>null</code> if this reference object has been cleared
 108      */
 109     public T get() {
 110         T o = super.get();
 111         if (o != null) this.timestamp = clock;

 112         return o;
 113     }
 114 
 115 }


  91      * @param referent object the new soft reference will refer to
  92      * @param q the queue with which the reference is to be registered,
  93      *          or <tt>null</tt> if registration is not required
  94      *
  95      */
  96     public SoftReference(T referent, ReferenceQueue<? super T> q) {
  97         super(referent, q);
  98         this.timestamp = clock;
  99     }
 100 
 101     /**
 102      * Returns this reference object's referent.  If this reference object has
 103      * been cleared, either by the program or by the garbage collector, then
 104      * this method returns <code>null</code>.
 105      *
 106      * @return   The object to which this reference refers, or
 107      *           <code>null</code> if this reference object has been cleared
 108      */
 109     public T get() {
 110         T o = super.get();
 111         if (o != null && this.timestamp != clock) 
 112             this.timestamp = clock;
 113         return o;
 114     }
 115 
 116 }