Interface CheckedConsumer<T>
- Type Parameters:
T- 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.
Checked Consumer - Consumer that can throw checked exceptions
可抛出受检异常的 Consumer - 扩展 JDK Consumer 支持受检异常
Extends JDK Consumer to allow throwing checked exceptions in lambdas.
扩展 JDK Consumer,支持在 lambda 中抛出受检异常。
Features | 主要功能:
- Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
- Convert to standard Consumer (unchecked) - 转换为标准 Consumer
- Silent execution (acceptQuietly) - 静默执行
- Composition with andThen - 组合操作
Usage Examples | 使用示例:
CheckedConsumer<Path> consumer = path -> Files.delete(path);
Consumer<Path> wrapped = consumer.unchecked();
consumer.acceptQuietly(path); // ignores exceptions
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 TypeMethodDescriptionvoidExecutes an operation that may throw a checked exception 执行操作,可能抛出受检异常default voidacceptQuietly(T t) Silently executes, ignoring exceptions 静默执行,忽略异常default CheckedConsumer<T> andThen(CheckedConsumer<? super T> after) Composes two CheckedConsumers 组合两个 CheckedConsumerstatic <T> CheckedConsumer<T> Wraps a standard Consumer as a CheckedConsumer 将普通 Consumer 包装为 CheckedConsumerConverts 转换为标准 Consumer,受检异常包装为 RuntimeException
-
Method Details
-
accept
-
unchecked
-
acceptQuietly
Silently executes, ignoring exceptions 静默执行,忽略异常- Parameters:
t- the value | 输入值
-
andThen
Composes two CheckedConsumers 组合两个 CheckedConsumer- Parameters:
after- the value | 后续操作- Returns:
- the result | 组合后的 CheckedConsumer
-
of
Wraps a standard Consumer as a CheckedConsumer 将普通 Consumer 包装为 CheckedConsumer- Type Parameters:
T- the value | 输入类型- Parameters:
consumer- the value | 普通 Consumer- Returns:
- CheckedConsumer
-