Interface CheckedRunnable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A Runnable that is allowed to throw checked exceptions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CheckedRunnableof(@NonNull CheckedRunnable methodReference) Creates aCheckedRunnablefrom the given method reference or lambda.voidrun()Executes the action, potentially performing side-effects.default RunnableReturns an uncheckedRunnablethat sneakily throws any exception encountered during execution of this unit of work.
-
Method Details
-
of
Creates aCheckedRunnablefrom the given method reference or lambda.Example usage:
// class Evil { static void sideEffect() { ... } } final CheckedRunnable checkedRunnable = CheckedRunnable.of(Evil::sideEffect); final Runnable runnable = checkedRunnable.unchecked(); // may or may not perform the side-effect without throwing checked exceptions runnable.run(); // may or may not perform the side-effect while potentially throwing runnable.run();- Parameters:
methodReference- typically a method reference, e.g.Type::method- Returns:
- a new
CheckedRunnablewrapping the given method reference - See Also:
-
run
-
unchecked
-