public class LazyConstructable<T>
extends java.lang.Object
get()
is
called the first time. User must provide LazyConstructable.Factory
that
actually constructs the value. Once the value is constructed, the factory is released
and may be collected by Java GC.
Threads: the class is thread-safe; how it's implementation is lock-free, so a
factory may be called several times from several concurrent threads. However
method get()
is guaranteed to always return the same value from to whatever
thread.
Modifier and Type | Class and Description |
---|---|
static interface |
LazyConstructable.Factory<T> |
Constructor and Description |
---|
LazyConstructable(LazyConstructable.Factory<T> factory) |
Modifier and Type | Method and Description |
---|---|
static <T> LazyConstructable<T> |
create(LazyConstructable.Factory<T> factory) |
T |
get()
Constructs a value when called first time and returns it to all subsequent calls.
|
public LazyConstructable(LazyConstructable.Factory<T> factory)
public static <T> LazyConstructable<T> create(LazyConstructable.Factory<T> factory)
public T get()
Copyright (c) IBM Corp. and others 2000, 2016. All Rights Reserved.