Interface CheckedCallable<V>
- Type Parameters:
V- return type - 返回值类型
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Checked Callable - Enhanced Callable with convenience methods
可抛出受检异常的 Callable - 增强 JDK Callable 提供便捷方法
Extends JDK Callable with additional convenience methods.
扩展 JDK Callable,提供额外的便捷方法。
Features | 主要功能:
- Convert to JDK Callable (toCallable) - 转换为 JDK Callable
- Silent execution (callQuietly/callOrDefault) - 静默执行
- Interop with CheckedSupplier - 与 CheckedSupplier 互操作
Usage Examples | 使用示例:
CheckedCallable<String> task = () -> Files.readString(path);
Future<String> future = executor.submit(task.toCallable());
String result = task.callOrDefault("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 TypeMethodDescriptioncall()Executes and returns a result, may throw a checked exception 执行并返回结果,可能抛出受检异常default VcallOrDefault(V defaultValue) Silently calls, returning the default value on exception 静默调用,异常时返回默认值default VSilently calls, returning null on exception 静默调用,异常时返回 nullstatic <V> CheckedCallable<V> from(CheckedSupplier<V> supplier) Converts a CheckedSupplier to a CheckedCallable 将 CheckedSupplier 转换为 CheckedCallablestatic <V> CheckedCallable<V> Wraps a JDK Callable as a CheckedCallable 将 JDK Callable 包装为 CheckedCallableConverts 转换为 JDK Callable
-
Method Details
-
call
-
toCallable
-
callQuietly
Silently calls, returning null on exception 静默调用,异常时返回 null- Returns:
- the result | 结果或 null
-
callOrDefault
-
of
Wraps a JDK Callable as a CheckedCallable 将 JDK Callable 包装为 CheckedCallable- Type Parameters:
V- the value | 返回值类型- Parameters:
callable- JDK Callable- Returns:
- CheckedCallable
-
from
Converts a CheckedSupplier to a CheckedCallable 将 CheckedSupplier 转换为 CheckedCallable- Type Parameters:
V- the value | 返回值类型- Parameters:
supplier- CheckedSupplier- Returns:
- CheckedCallable
-