Interface CheckedFunction<T,R>
- Type Parameters:
T- input type - 输入类型R- 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 Function - Function that can throw checked exceptions
可抛出受检异常的 Function - 扩展 JDK Function 支持受检异常
Extends JDK Function to allow throwing checked exceptions in lambdas.
扩展 JDK Function,支持在 lambda 中抛出受检异常。
Features | 主要功能:
- Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
- Convert to standard Function (unchecked) - 转换为标准 Function
- Silent execution (applyQuietly/applyOrDefault) - 静默执行
- Composition (andThen/compose) - 函数组合
Usage Examples | 使用示例:
CheckedFunction<Path, String> reader = path -> Files.readString(path);
paths.stream().map(reader.unchecked()).toList();
String result = reader.applyOrDefault(path, "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 TypeMethodDescriptiondefault <V> CheckedFunction<T, V> andThen(CheckedFunction<? super R, ? extends V> after) Composes functions (executes this function first, then after) 组合函数(先执行本函数,再执行 after)Applies the function, may throw a checked exception 应用函数,可能抛出受检异常default RapplyOrDefault(T t, R defaultValue) Silently applies, returning the default value on exception 静默应用,异常时返回默认值default RapplyQuietly(T t) Silently applies, returning null on exception 静默应用,异常时返回 nulldefault <V> CheckedFunction<V, R> compose(CheckedFunction<? super V, ? extends T> before) Composes functions (executes before first, then this function) 组合函数(先执行 before,再执行本函数)static <T> CheckedFunction<T, T> identity()Creates 创建恒等函数static <T,R> CheckedFunction <T, R> Wraps a standard Function as a CheckedFunction 将普通 Function 包装为 CheckedFunctionConverts 转换为标准 Function,受检异常包装为 RuntimeException
-
Method Details
-
apply
-
unchecked
-
applyQuietly
-
applyOrDefault
-
andThen
Composes functions (executes this function first, then after) 组合函数(先执行本函数,再执行 after)- Type Parameters:
V- the value | 最终返回类型- Parameters:
after- the value | 后续函数- Returns:
- the result | 组合后的函数
-
compose
Composes functions (executes before first, then this function) 组合函数(先执行 before,再执行本函数)- Type Parameters:
V- the value | 输入类型- Parameters:
before- the value | 前置函数- Returns:
- the result | 组合后的函数
-
of
Wraps a standard Function as a CheckedFunction 将普通 Function 包装为 CheckedFunction- Type Parameters:
T- the value | 输入类型R- the value | 返回值类型- Parameters:
function- the value | 普通 Function- Returns:
- CheckedFunction
-
identity
Creates 创建恒等函数- Type Parameters:
T- the type | 类型- Returns:
- the result | 恒等函数
-