Interface LazyResettable<C>

All Superinterfaces:
Lazy<C>
All Known Implementing Classes:
LazyResettableImpl, LazyResettableWithTearDown

public interface LazyResettable<C> extends Lazy<C>
This, like Lazy, implements the same API as Optional and provides late initialization for its content. Contrarily to Lazy, however, this interface provides a reset() function to return to the original, uninitialized, state, after which the late initialization can occur again, on-demand. This allows the user to define a member variable as final, and thus guarantee that there is only one statement which can define the Supplier used in the initialization of the content, rather than declare a non-final Lazy and rely on convention to always reset it to a new reference that happens to carry the same Supplier.
  • Method Details

    • reset

      void reset()
      Returns to the uninitialized state.
    • of

      static <C> LazyResettable<C> of(Supplier<C> supplier)
      Parameters:
      supplier - to initialize the wrapped value
      Returns:
      an instance of Lazy which will execute the if needed
    • of

      static <C> LazyResettable<C> of(Supplier<C> supplier, Consumer<C> tearDown)
      Parameters:
      supplier - to initialize the wrapped value
      tearDown - to run on thw wrapped value during reset, if it has already been initialized
      Returns:
      an instance of Lazy which will execute the if needed