java.lang.Object
org.eclipse.milo.opcua.stack.core.util.Lazy<T>
Type Parameters:
T - the type of value computed and held.

public final class Lazy<T> extends Object
Thread-safe holder for a lazily-computed value.
  • Constructor Details

    • Lazy

      public Lazy()
  • Method Details

    • get

      public T get(Supplier<T> supplier)
      Get the lazily computed value, computing it if necessary using supplier.

      null values returned by the supplier are not held, i.e. the next call will compute the value again.

      Parameters:
      supplier - a Supplier that computes the value if necessary.
      Returns:
      the lazily computed value.
    • getOrThrow

      public <E extends Exception> T getOrThrow(Lazy.ThrowingSupplier<E,T> supplier) throws E
      Get the lazily computed value, computing it if necessary using supplier.

      null values returned by the supplier are not held, i.e. the next call will compute the value again.

      Parameters:
      supplier - a Lazy.ThrowingSupplier that computes the value if necessary.
      Returns:
      the lazily computed value.
      Throws:
      E - if the supplier throws an exception.
    • set

      public void set(T value)
      Set the value.
      Parameters:
      value - the value to set.
    • reset

      public void reset()
      Reset the value to null.