类 SingletonSupplier<T>
java.lang.Object
cn.taketoday.util.function.SingletonSupplier<T>
- 类型参数:
T- the type of results supplied by this supplier
- 所有已实现的接口:
Supplier<T>
A
Supplier decorator that caches a singleton result and
makes it available from get() (nullable) and obtain() (null-safe).
A SingletonSupplier can be constructed via of factory methods
or via constructors that provide a default supplier as a fallback. This is
particularly useful for method reference suppliers, falling back to a default
supplier for a method that returned null and caching the result.
From spring
- 从以下版本开始:
- 3.0
- 作者:
- Juergen Hoeller, TODAY 2021/3/25 11:38
-
构造器概要
构造器构造器说明SingletonSupplier(Supplier<? extends T> instanceSupplier, Supplier<? extends T> defaultSupplier) Build aSingletonSupplierwith the given instance supplier and a default supplier for the case when the instance isnull.SingletonSupplier(T instance, Supplier<? extends T> defaultSupplier) Build aSingletonSupplierwith the given singleton instance and a default supplier for the case when the instance isnull. -
方法概要
修饰符和类型方法说明static <T> SingletonSupplier<T>Build aSingletonSupplierwith the given supplier.get()Get the shared singleton instance for this supplier.obtain()Obtain the shared singleton instance for this supplier.static <T> SingletonSupplier<T>ofNullable(Supplier<T> supplier) Build aSingletonSupplierwith the given supplier.static <T> SingletonSupplier<T>ofNullable(T instance) Build aSingletonSupplierwith the given singleton instance.static <T> SingletonSupplier<T>valueOf(T instance) Build aSingletonSupplierwith the given singleton instance.
-
构造器详细资料
-
SingletonSupplier
Build aSingletonSupplierwith the given singleton instance and a default supplier for the case when the instance isnull.- 参数:
instance- the singleton instance (potentiallynull)defaultSupplier- the default supplier as a fallback
-
SingletonSupplier
public SingletonSupplier(@Nullable Supplier<? extends T> instanceSupplier, Supplier<? extends T> defaultSupplier) Build aSingletonSupplierwith the given instance supplier and a default supplier for the case when the instance isnull.- 参数:
instanceSupplier- the immediate instance supplierdefaultSupplier- the default supplier as a fallback
-
-
方法详细资料
-
get
Get the shared singleton instance for this supplier. -
obtain
Obtain the shared singleton instance for this supplier.- 返回:
- the singleton instance (never
null) - 抛出:
IllegalStateException- in case of no instance
-
valueOf
Build aSingletonSupplierwith the given singleton instance.- 参数:
instance- the singleton instance (nevernull)- 返回:
- the singleton supplier (never
null)
-
ofNullable
Build aSingletonSupplierwith the given singleton instance.- 参数:
instance- the singleton instance (potentiallynull)- 返回:
- the singleton supplier, or
nullif the instance wasnull
-
from
Build aSingletonSupplierwith the given supplier.- 参数:
supplier- the instance supplier (nevernull)- 返回:
- the singleton supplier (never
null)
-
ofNullable
Build aSingletonSupplierwith the given supplier.- 参数:
supplier- the instance supplier (potentiallynull)- 返回:
- the singleton supplier, or
nullif the instance supplier wasnull
-