Ether Framework
Unified API docs for Ether modules
Loading...
Searching...
No Matches
dev.rafex.ether.di.Lazy< T > Class Template Reference

Thread-safe lazy initializer using double-checked locking. More...

Collaboration diagram for dev.rafex.ether.di.Lazy< T >:

Public Member Functions

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.

Detailed Description

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()));
Parameters
<T>type of the lazily-initialized value

Definition at line 46 of file Lazy.java.

Constructor & Destructor Documentation

◆ Lazy()

dev.rafex.ether.di.Lazy< T >.Lazy ( final Supplier< T > supplier)

Creates a new Lazy backed by the given supplier.

Parameters
supplierfactory for the value; called at most once; must not return null

Definition at line 56 of file Lazy.java.

Member Function Documentation

◆ get()

T dev.rafex.ether.di.Lazy< T >.get ( )

Returns the lazily-initialized value, initializing it on first call.

Returns
the value produced by the supplier
Exceptions
NullPointerExceptionif the supplier returned null

Definition at line 66 of file Lazy.java.

◆ isInitialized()

boolean dev.rafex.ether.di.Lazy< T >.isInitialized ( )

Returns true if the value has already been initialized.

Returns
true after the first call to get() completes

Definition at line 86 of file Lazy.java.


The documentation for this class was generated from the following file:
  • ether-di/ether-di/src/main/java/dev/rafex/ether/di/Lazy.java