Interface Lazy<T>
- Type Parameters:
T- type of value
- All Superinterfaces:
Supplier<T>
- All Known Implementing Classes:
LazyUtil.Constant, LazyUtil.PureLazy, LazyUtil.SafeLazy, LazyUtil.WeakConstant
Provides a lazily-initialized value from a
Supplier<T>.- Since:
- 2.22.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault Tget()Returns the value held by this lazy.booleanIndicates whether this lazy value has been initialized.static <T> Lazy<T> Creates a strict lazy value using the provided Supplier.default <R> Lazy<R> Creates a new lazy value derived from this lazy value using the provided value mapping function.static <T> Lazy<T> Creates a pure lazy value using the provided Supplier to initialize the value.voidSets this lazy value to the provided value.value()Returns the value held by this lazy.static <T> Lazy<T> value(T value) Creates a lazy value using the provided constant value.static <T> Lazy<T> weak(T value) Creates a lazy value using a weak reference to the provided value.
-
Method Details
-
value
T value()Returns the value held by this lazy. This may cause the value to initialize if it hasn't been already. -
get
-
map
-
isInitialized
boolean isInitialized()Indicates whether this lazy value has been initialized. -
set
Sets this lazy value to the provided value.- Throws:
UnsupportedOperationException- if this type of lazy value cannot be updated
-
lazy
-
value
Creates a lazy value using the provided constant value. -
weak
Creates a lazy value using a weak reference to the provided value. -
pure
Creates a pure lazy value using the provided Supplier to initialize the value. The supplier may be invoked more than once, and the return value should be a purely computed value as the result may be a different instance each time. This is useful for building cache tables and other pure computations.
-