Class LazyReference<T>
java.lang.Object
io.github.cowwoc.pouch10.core.LazyReference<T>
- Type Parameters:
T- the type of object being referenced
- All Implemented Interfaces:
Reference<T>
A reference that initializes a value on demand.
Instances of LazyFactory are not safe for use by multiple threads. If such synchronization is
required then it is recommended that ConcurrentLazyReference be used.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> LazyReference<T> Creates a newLazyReference.protected abstract TCreates the value.getValue()Returns the value.booleanIndicates if the value was initialized.toString()
-
Constructor Details
-
LazyReference
protected LazyReference()Creates a new instance.
-
-
Method Details
-
create
Creates a newLazyReference.- Type Parameters:
T- the type of value returned by the reference- Parameters:
supplier- supplies the reference value- Returns:
- a new
LazyReference
-
createValue
Creates the value. This method is invoked the first timeReference.getValue()is invoked.- Returns:
- the value
-
isInitialized
public boolean isInitialized()Description copied from interface:ReferenceIndicates if the value was initialized.A value may get initialized immediately after this method returns
falsebut once it returnstrueit will continue to do so indefinitely.- Specified by:
isInitializedin interfaceReference<T>- Returns:
trueif the value was initialized
-
getValue
-
toString
-