Interface CheckedSupplier<T>
- Type Parameters:
T- return type - 返回值类型
- All Known Subinterfaces:
ExceptionUtil.CheckedSupplier<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Checked Supplier - Supplier that can throw checked exceptions
可抛出受检异常的 Supplier - 扩展 JDK Supplier 支持受检异常
Extends JDK Supplier to allow throwing checked exceptions in lambdas.
扩展 JDK Supplier,支持在 lambda 中抛出受检异常。
Features | 主要功能:
- Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
- Convert to standard Supplier (unchecked) - 转换为标准 Supplier
- Silent execution (getQuietly/getOrDefault) - 静默执行
Usage Examples | 使用示例:
CheckedSupplier<String> supplier = () -> Files.readString(path);
Supplier<String> wrapped = supplier.unchecked();
String result = supplier.getOrDefault("fallback");
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionget()Gets 获取结果,可能抛出受检异常default TgetOrDefault(T defaultValue) Silently executes, returning the default value on exception 静默执行,异常时返回默认值default TSilently executes, returning null on exception 静默执行,异常时返回 nullstatic <T> CheckedSupplier<T> Wraps a standard Supplier as a CheckedSupplier 将普通 Supplier 包装为 CheckedSupplierConverts 转换为标准 Supplier,受检异常包装为 RuntimeException
-
Method Details
-
get
-
unchecked
-
getQuietly
Silently executes, returning null on exception 静默执行,异常时返回 null- Returns:
- the result | 结果或 null
-
getOrDefault
-
of
Wraps a standard Supplier as a CheckedSupplier 将普通 Supplier 包装为 CheckedSupplier- Type Parameters:
T- the value | 返回值类型- Parameters:
supplier- the value | 普通 Supplier- Returns:
- CheckedSupplier
-