Package me.sbasalaev

Class Lazy<T>

java.lang.Object
me.sbasalaev.Lazy<T>
Type Parameters:
T - the type of the value, may be nullable.
All Implemented Interfaces:
Supplier<T>

public final class Lazy<@Out T> extends Object implements Supplier<T>
Lazily evaluated value. This class is thread-safe, the evaluation of the value only happens once and it is safe to call get() simultaneously from different threads.
Since:
1.1
  • Constructor Details

    • Lazy

      public Lazy(Supplier<@Out T> supplier)
      Creates new instance that lazily evaluates the value from the supplier.
    • Lazy

      public Lazy(@Out T value)
      Creates new instance with the value that is already evaluated.
  • Method Details

    • get

      public T get()
      Evaluates and returns the value. If value is already evaluated, just returns it.
      Specified by:
      get in interface Supplier<T>
    • isEvaluated

      public boolean isEvaluated()
      True iff value is already evaluated.
    • toString

      public String toString()
      Overrides:
      toString in class Object