Interface CheckedRunnable
- All Known Subinterfaces:
ExceptionUtil.CheckedRunnable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Checked Runnable - Runnable that can throw checked exceptions
可抛出受检异常的 Runnable - 扩展 JDK Runnable 支持受检异常
Extends JDK Runnable to allow throwing checked exceptions in lambdas.
扩展 JDK Runnable,支持在 lambda 中抛出受检异常。
Features | 主要功能:
- Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
- Convert to standard Runnable (unchecked) - 转换为标准 Runnable
- Silent execution (runQuietly) - 静默执行
- Composition with andThen - 组合操作
Usage Examples | 使用示例:
CheckedRunnable task = () -> Files.delete(tempFile);
Runnable wrapped = task.unchecked();
task.runQuietly(); // 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 TypeMethodDescriptiondefault CheckedRunnableandThen(CheckedRunnable after) Composes two CheckedRunnables 组合两个 CheckedRunnablestatic CheckedRunnableWraps a standard Runnable as a CheckedRunnable 将普通 Runnable 包装为 CheckedRunnablevoidrun()Executes an operation that may throw a checked exception 执行操作,可能抛出受检异常default voidSilently executes, ignoring exceptions 静默执行,忽略异常default RunnableConverts 转换为标准 Runnable,受检异常包装为 RuntimeException
-
Method Details
-
run
-
unchecked
-
runQuietly
default void runQuietly()Silently executes, ignoring exceptions 静默执行,忽略异常 -
andThen
Composes two CheckedRunnables 组合两个 CheckedRunnable- Parameters:
after- the value | 后续操作- Returns:
- the result | 组合后的 CheckedRunnable
-
of
Wraps a standard Runnable as a CheckedRunnable 将普通 Runnable 包装为 CheckedRunnable- Parameters:
runnable- the value | 普通 Runnable- Returns:
- CheckedRunnable
-