Package eu.bandm.tools.util.java
Class Lazy<T>
java.lang.Object
eu.bandm.tools.util.java.Lazy<T>
- Type Parameters:
T
- the type of the supplied value
- All Implemented Interfaces:
Supplier<T>
A lazy supplier of a single value.
A lazy supplier only supplies a single value, i.e., all subsequent calls
to get()
return a value identical to the first one. Any side
effects of creating the returned value only occur on the first call to get()
. Side effects are encapsulated by giving a initialization supplier.
This class is not inherently thread-safe. If an instance is to be shared
between threads, and there is a race where multiple threads may call
get()
, then there is no guarantee how many times the given initialization
supplier will be called, or which respective result will be stored. If
unique initialization is required, add external synchronization as needed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget()
Returns the value, calling the initializer if necessary.boolean
Checks whether the initializer has been called.
-
Constructor Details
-
Lazy
Creates a new instance.The given initializer is stored, but not yet evaluated.
- Parameters:
init
- the initializer- Throws:
NullPointerException
- ifinit
is null
-
-
Method Details