Thread-safe lazy initializer using double-checked locking. More...
Public Member Functions | |
| T | get () |
| Returns the lazily-initialized value, initializing it on first call. | |
| boolean | isInitialized () |
Returns true if the value has already been initialized. | |
| Lazy (final Supplier< T > supplier) | |
Creates a new Lazy backed by the given supplier. | |
Thread-safe lazy initializer using double-checked locking.
The supplier is called at most once, on the first call to get(). After initialization the supplier reference is cleared so the supplier itself (and any objects it closes over) can be garbage-collected.
var config = new Lazy<>(AppConfig::load);
var database = new Lazy<>(() -> DataSource.create(config.get()));
| <T> | type of the lazily-initialized value |
| dev.rafex.ether.di.Lazy< T >.Lazy | ( | final Supplier< T > | supplier | ) |
| T dev.rafex.ether.di.Lazy< T >.get | ( | ) |
| boolean dev.rafex.ether.di.Lazy< T >.isInitialized | ( | ) |