Class LazyValue<T>

java.lang.Object
org.mule.amf.impl.util.LazyValue<T>
Type Parameters:
T - the generic type of the provided value
All Implemented Interfaces:
Supplier<T>

public class LazyValue<T> extends Object implements Supplier<T>
Provides a value which may be lazily computed.

The value is only computed on the first invokation of get(). Subsequent calls to such method will always return the same value.

This class is thread-safe. When invoking get(), it is guaranteed that the value will be computed only once.

Since:
1.0
  • Constructor Details

    • LazyValue

      public LazyValue(Supplier<T> supplier)
      Creates a new instance which lazily obtains its value from the given supplier. It is guaranteed that Supplier.get() will only be invoked once. Because this class is thread-safe, the supplier is not required to be.
      Parameters:
      supplier - A Supplier through which the value is obtained
  • Method Details

    • get

      public T get()
      Returns the lazy value. If the value has not yet been computed, then it does so
      Specified by:
      get in interface Supplier<T>
      Returns:
      the lazy value