T
- the type of the value to be initializedpublic final class LazyInit<T>
extends java.lang.Object
implements java.util.function.Supplier<T>
Example use:
private final LazyInit<Foo> foo = LazyInit.of(() -> expensiveFooConstruction());
void useFoo() {
Foo foo = this.foo.get();
// Do thing with foo
}
Constructor and Description |
---|
LazyInit(java.util.concurrent.Callable<? extends T> initializer)
Creates a new lazy initializer.
|
Modifier and Type | Method and Description |
---|---|
T |
get()
Gets the value, initializing it if necessary.
|
static <T> LazyInit<T> |
of(java.util.concurrent.Callable<? extends T> initializer)
Creates a new lazy initializer.
|
public LazyInit(java.util.concurrent.Callable<? extends T> initializer)
initializer
- the function to use to initialize the value when it is first accessedpublic static <T> LazyInit<T> of(java.util.concurrent.Callable<? extends T> initializer)
T
- the type of the value to be initializedinitializer
- the function to use to initialize the value when it is first accessedpublic T get()
get
in interface java.util.function.Supplier<T>
java.lang.RuntimeException
- if initialization failed