Class Lazy<T>

  • Type Parameters:
    T - Type of object.
    All Implemented Interfaces:
    Serializable

    public final class Lazy<T>
    extends Object
    implements Serializable
    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
    See Also:
    Serialized Form
    • Method Detail

      • get

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