Module de.carne
Package de.carne.util

Class Lazy<T>

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

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

      Constructors 
      Constructor Description
      Lazy​(java.util.function.Supplier<@NonNull T> initializer)
      Construct Lazy.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()
      Get the object.
      java.util.Optional<T> getOptional()
      Gets the object as an Optional.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • Lazy

        public Lazy​(java.util.function.Supplier<@NonNull T> initializer)
        Construct Lazy.
        Parameters:
        initializer - The Supplier to use for object initialization.
    • Method Detail

      • get

        public T get()
        Get the object.

        The actual object will be created lazily the first time this function is invoked.

        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