Package io.vavr
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.
@FunctionalInterface public interface CheckedRunnableA Runnable that is allowed to throw checked exceptions.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static CheckedRunnableof(@NonNull CheckedRunnable methodReference)Creates aCheckedRunnablefrom the given method reference or lambda.voidrun()Executes the action, potentially performing side-effects.default java.lang.Runnableunchecked()Returns an uncheckedRunnablethat sneakily throws any exception encountered during execution of this unit of work.
-
-
-
Method Detail
-
of
static CheckedRunnable of(@NonNull CheckedRunnable methodReference)
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:
CheckedFunction1.of(CheckedFunction1)
-
run
void run() throws java.lang.Throwable
Executes the action, potentially performing side-effects.- Throws:
java.lang.Throwable- if an error occurs during execution
-
unchecked
default java.lang.Runnable unchecked()
Returns an uncheckedRunnablethat sneakily throws any exception encountered during execution of this unit of work.- Returns:
- a
Runnablethat may throw anyThrowablewithout declaring it
-
-