Class LazyValue<T>

java.lang.Object
nl.pim16aap2.util.LazyValue<T>
Type Parameters:
T - The type of the object to initialize lazily.
All Implemented Interfaces:
dagger.Lazy<T>

@ThreadSafe public final class LazyValue<T> extends Object implements dagger.Lazy<T>
Represents a lazily initialized object.

Initialization is thread-safe.

  • Constructor Summary

    Constructors
    Constructor
    Description
    LazyValue(Supplier<T> supplier)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Note that calling this method will result in get() being called for both objects if the other object is also a LazyValue.
    get()
    Gets the lazily initialized object.
    int
    Note that calling this method will result in get() being called.
    boolean
    Checks whether the lazily initialized value has been initialized yet.
    @Nullable T
    Resets the lazily initialized value (if it has been initialized yet).
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LazyValue

      public LazyValue(Supplier<T> supplier)
      Parameters:
      supplier - The supplier to use to create the instance of the object when needed.

      Note that the return value may not be null!

  • Method Details

    • get

      public T get()
      Gets the lazily initialized object. If it does not exist yet, a new instance will be created using supplier.
      Specified by:
      get in interface dagger.Lazy<T>
      Returns:
      The lazily initialized object.
    • isInitialized

      public boolean isInitialized()
      Checks whether the lazily initialized value has been initialized yet.
      Returns:
      True if the value has been initialized, false otherwise.
    • reset

      public @Nullable T reset()
      Resets the lazily initialized value (if it has been initialized yet).
      Returns:
      The previously-initialized value or null if it was not initialized yet.
    • equals

      public boolean equals(Object o)
      Note that calling this method will result in get() being called for both objects if the other object is also a LazyValue.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Note that calling this method will result in get() being called.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object