1 package org.djutils.event.reference;
2
3 /**
4 * A WeakReference. The WeakReference extends the <code>java.lang.ref.WeakReference</code> and besides implementing the
5 * Reference interface no changes are defined.
6 * <p>
7 * Copyright (c) 2002-2025 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
8 * for project information <a href="https://djutils.org" target="_blank"> https://djutils.org</a>. The DJUTILS project is
9 * distributed under a three-clause BSD-style license, which can be found at
10 * <a href="https://djutils.org/docs/license.html" target="_blank"> https://djutils.org/docs/license.html</a>. This class was
11 * originally part of the DSOL project, see <a href="https://simulation.tudelft.nl/dsol/manual" target="_blank">
12 * https://simulation.tudelft.nl/dsol/manual</a>.
13 * </p>
14 * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a>
15 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16 * @param <T> the type of the reference
17 */
18 public class WeakReference<T> extends Reference<T>
19 {
20 /** the wrapped reference to the referent. */
21 private final transient java.lang.ref.WeakReference<T> referent;
22
23 /**
24 * Creates a new weak reference that refers to the given object. The new reference is not registered with any queue.
25 * @param referent object the new weak reference will refer to
26 */
27 public WeakReference(final T referent)
28 {
29 this.referent = new java.lang.ref.WeakReference<T>(referent);
30 }
31
32 @Override
33 public final T get()
34 {
35 return this.referent.get();
36 }
37 }