Package com.seeq.utilities
Class ClearableReference<T>
java.lang.Object
com.seeq.utilities.ClearableReference<T>
- Type Parameters:
T
- The type of object to be wrapped inside the ClearableReference
A ClearableReference wraps an object inside another object. When a method parameter is reassigned in a method, it
does not affect the original reference from the calling method. This class provides a way for "reassignments" to
happen and affect the calling method. In particular, this can be used to pass an object into a method while clearing
the calling method's reference to it, which can help plug memory leaks.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a ClearableReference that does not refer to anything yet.ClearableReference
(T value) Create a ClearableReference that refers to the argument. -
Method Summary
-
Constructor Details
-
ClearableReference
public ClearableReference()Create a ClearableReference that does not refer to anything yet. -
ClearableReference
Create a ClearableReference that refers to the argument.- Parameters:
value
- The object this ClearableReference should refer to.
-
-
Method Details
-
set
Set the object this ClearableReference refers to.- Parameters:
value
- The object this ClearableReference should refer to.
-
get
Get the object this ClearableReference refers to.- Returns:
- The object this ClearableReference refers to.
-
clear
public void clear()Clear the reference to the object currently referred to. -
getAndClear
Clear the reference to the object currently referred to and return it.- Returns:
- The object this ClearableReference will no longer refer to.
-