Class Lazy<T>

java.lang.Object
net.neoforged.neoforge.common.util.Lazy<T>
Type Parameters:
T - The type of the value
All Implemented Interfaces:
Supplier<T>

public final class Lazy<T> extends Object implements Supplier<T>
Proxy object for a value that is calculated on first access, and can be refreshed as well.
  • Field Details

    • delegate

      private final Supplier<T> delegate
    • cachedValue

      @Nullable private volatile T cachedValue
  • Constructor Details

  • Method Details

    • of

      public static <T> Lazy<T> of(Supplier<T> supplier)
      Constructs a lazy-initialized object.
      Parameters:
      supplier - The supplier for the value, to be called the first time the value is needed, or whenever the cache has been invalidated.
    • invalidate

      public void invalidate()
      Invalidates the cache, causing the supplier to be called again on the next access.
    • get

      public T get()
      Specified by:
      get in interface Supplier<T>