Class Lazy<T>

java.lang.Object
eu.bandm.tools.util.java.Lazy<T>
Type Parameters:
T - the type of the supplied value
All Implemented Interfaces:
Supplier<T>

public class Lazy<T> extends Object implements Supplier<T>
A lazy supplier of a single value.

A lazy supplier only supplies a single value, i.e., all subsequent calls to get() return a value identical to the first one. Any side effects of creating the returned value only occur on the first call to get(). Side effects are encapsulated by giving a initialization supplier.

This class is not inherently thread-safe. If an instance is to be shared between threads, and there is a race where multiple threads may call get(), then there is no guarantee how many times the given initialization supplier will be called, or which respective result will be stored.

  • Constructor Details

    • Lazy

      public Lazy(Supplier<? extends T> init)
  • Method Details

    • get

      public T get()
      Specified by:
      get in interface Supplier<T>
    • isInitialized

      public boolean isInitialized()