Class Lazy<T>

  • Type Parameters:
    T - Type of object.

    public final class Lazy<T>
    extends Object
    Implements lazy-initialized object primarily for final and transient fields. Utilizes double-checked locking for optimization.

    Example:

     
     private final Lazy<Object> lazy = new Lazy<>(Object::new);
     Object lazyInstance = lazy.get();
     
     

    Example Code (GitHub)

    Since:
    3.9
    Author:
    Lenny Primak
    • Constructor Detail

      • Lazy

        public Lazy​(Supplier<T> initFunction)
    • Method Detail

      • get

        public T get()
        Returns underlying object, initialize when necessary.
        Returns:
        Underlying object, initialize when necessary.