Interface CheckedBiConsumer<T,U>
- Type Parameters:
T- first input type - 第一个输入类型U- second input type - 第二个输入类型
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
CheckedBiConsumer - BiConsumer that can throw checked exceptions
CheckedBiConsumer - 可抛出受检异常的双参消费者
Extends the concept of JDK BiConsumer to allow throwing checked exceptions.
扩展 JDK BiConsumer 的概念,支持抛出受检异常。
Features | 主要功能:
- Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
- Convert to standard BiConsumer (unchecked) - 转换为标准 BiConsumer
- Silent execution - 静默执行
- Chaining support (andThen) - 支持链式调用
Usage Examples | 使用示例:
CheckedBiConsumer<Path, String> writer =
(path, content) -> Files.writeString(path, content);
BiConsumer<Path, String> wrapped = writer.unchecked();
writer.acceptQuietly(path, content);
// Chaining
writer.andThen((p, c) -> log.info("Written to " + p))
.accept(path, content);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-functional V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidAccept inputs, may throw checked exception 接受输入,可能抛出受检异常default voidacceptQuietly(T t, U u) default CheckedBiConsumer<T, U> andThen(CheckedBiConsumer<? super T, ? super U> after) Chain with another consumer (execute this, then after) 与另一个消费者链接(先执行本函数,再执行 after)static <T,U> CheckedBiConsumer <T, U> of(BiConsumer<T, U> consumer) Wrap a standard BiConsumer as CheckedBiConsumer 将标准 BiConsumer 包装为 CheckedBiConsumerdefault BiConsumer<T, U> Convert to standard BiConsumer, wrapping checked exceptions 转换为标准 BiConsumer,包装受检异常
-
Method Details
-
accept
-
unchecked
Convert to standard BiConsumer, wrapping checked exceptions 转换为标准 BiConsumer,包装受检异常- Returns:
- BiConsumer that wraps checked exceptions - 包装受检异常的 BiConsumer
-
acceptQuietly
-
andThen
Chain with another consumer (execute this, then after) 与另一个消费者链接(先执行本函数,再执行 after)- Parameters:
after- consumer to execute after this - 在本函数之后执行的消费者- Returns:
- chained consumer - 链式消费者
-
of
Wrap a standard BiConsumer as CheckedBiConsumer 将标准 BiConsumer 包装为 CheckedBiConsumer- Type Parameters:
T- first input type - 第一个输入类型U- second input type - 第二个输入类型- Parameters:
consumer- standard BiConsumer - 标准 BiConsumer- Returns:
- CheckedBiConsumer wrapper - CheckedBiConsumer 包装器
-