Class Late<T>

  • Type Parameters:
    T - the actual object type.
    All Implemented Interfaces:
    java.util.function.Supplier<T>

    public class Late<@NonNull T>
    extends java.lang.Object
    implements java.util.function.Supplier<T>
    Utility class used to handle late initialized objects in a null-safe way.
    • Constructor Summary

      Constructors 
      Constructor Description
      Late()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()
      Gets the object.
      java.util.Optional<T> getOptional()
      Gets the object as an Optional.
      T set​(java.util.function.Supplier<@NonNull T> supplier)
      Sets/initializes the object.
      @NonNull T set​(@NonNull T object)
      Sets/initializes the object.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Late

        public Late()
    • Method Detail

      • set

        public @NonNull T set​(@NonNull T object)
        Sets/initializes the object.
        Parameters:
        object - the object to set.
        Returns:
        the set object.
      • set

        public T set​(java.util.function.Supplier<@NonNull T> supplier)
        Sets/initializes the object.
        Parameters:
        supplier - the Supplier providing the object to set.
        Returns:
        the set object.
      • get

        public T get()
        Gets the object.

        If the object has not yet been set/initialized an IllegalStateException will be thrown.

        Specified by:
        get in interface java.util.function.Supplier<T>
        Returns:
        the object.
      • getOptional

        public java.util.Optional<T> getOptional()
        Gets the object as an Optional.
        Returns:
        the object as an Optional.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object