View Javadoc

1   /*
2    * @(#) WeakReference.java Dec 9, 2003 Copyright (c) 2002-2005 Delft University
3    * of Technology Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights
4    * reserved. This software is proprietary information of Delft University of
5    * Technology The code is published under the Lesser General Public License
6    */
7   package nl.tudelft.simulation.event.ref;
8   
9   /***
10   * A WeakReference. The weakreference extends the
11   * <code>java.lang.ref.WeakReference</code> and besides implementing the
12   * Reference interface no changes are defined.
13   * <p>
14   * (c) copyright 2002-2005 <a href="http://www.simulation.tudelft.nl">Delft
15   * University of Technology </a>, the Netherlands.
16   * <p>
17   * See for project information <a
18   * href="http://www.simulation.tudelft.nl/dsol/event">www.simulation.tudelft.nl/event
19   * </a> <br>
20   * License of use: <a href="http://www.gnu.org/copyleft/lesser.html">Lesser
21   * General Public License (LGPL) </a>, no warranty
22   * 
23   * @author <a href="http://www.peter-jacobs.com">Peter Jacobs </a>
24   * @version $Revision: 1.8 $ $Date: 2005/08/04 12:08:33 $
25   * @since 1.5
26   * @param <T> the type of the reference
27   */
28  public class WeakReference<T> extends Reference<T>
29  {
30      /*** the reference */
31      private transient java.lang.ref.WeakReference<T> reference = null;
32  
33      /***
34       * Creates a new weak reference that refers to the given object. The new
35       * reference is not registered with any queue.
36       * 
37       * @param referent object the new weak reference will refer to
38       */
39      public WeakReference(final T referent)
40      {
41          this.reference = new java.lang.ref.WeakReference<T>(referent);
42      }
43  
44      /***
45       * @see nl.tudelft.simulation.event.ref.Reference#get()
46       */
47      @Override
48  	public T get()
49      {
50          return this.reference.get();
51      }
52  
53      /***
54       * @see nl.tudelft.simulation.event.ref.Reference#set(java.lang.Object)
55       */
56      @Override
57  	protected void set(final T value)
58      {
59          this.reference = new java.lang.ref.WeakReference<T>(value);
60      }
61  }