T - the type of the embed value@ParametersAreNonnullByDefault public abstract class LazyReference<T> extends Object
T by using a Supplier. The value is wrapped in a
Reference that is automatically refreshed on-demand when it has been cleared, either by the program or by the
garbage collector.Reference| Constructor and Description |
|---|
LazyReference(Supplier<T> refreshFunction)
Constructs a new
LazyReference. |
| Modifier and Type | Method and Description |
|---|---|
T |
get()
Gets the value.
|
protected abstract Reference<T> |
newReference(T value)
Creates a new
Reference for the given value. |
static <T> LazyReference<T> |
soft(Supplier<T> refreshFunction)
Creates a new lazy reference that uses
SoftReference. |
void |
update(T newValue)
Updates the value.
|
static <T> LazyReference<T> |
weak(Supplier<T> refreshFunction)
Creates a new lazy reference that uses
WeakReference. |
public static <T> LazyReference<T> soft(Supplier<T> refreshFunction)
SoftReference.T - the type of the embed valuerefreshFunction - the function used to refresh the valuepublic static <T> LazyReference<T> weak(Supplier<T> refreshFunction)
WeakReference.T - the type of the embed valuerefreshFunction - the function used to refresh the valuepublic T get()
public void update(@Nullable T newValue)
newValue - the new valueCopyright © 2017–2019 Atlanmod. All rights reserved.