Package de.marcely.bedwars.tools
Class LazyReference<T>
java.lang.Object
de.marcely.bedwars.tools.LazyReference<T>
- Type Parameters:
T
- The type of the reference
- All Implemented Interfaces:
Supplier<T>
Represents a lazy reference that will only be initialized when it's being accessed.
After the initial access, the reference will be cached and returned on every subsequent access.
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
LazyReference
Creates a new lazy reference.- Parameters:
factory
- The factory that will be called when the reference is being accessed
-
-
Method Details
-
get
Gets the reference.- Specified by:
get
in interfaceSupplier<T>
- Returns:
- The reference
- Throws:
IllegalStateException
- If the factory returns null
-
clear
public void clear()Clears the cached reference. -
of
Creates a new lazy reference.- Type Parameters:
T
- The type of the reference- Parameters:
factory
- The factory that will be called when the reference is being accessed- Returns:
- The new lazy reference
-