Package de.xima.fc.interfaces
Interface IThrowingRunnable
- All Superinterfaces:
Runnable
- 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 may throw a checked exception.
This interface is designed to provide a common protocol for objects that wish to execute code
This is a functional interface
whose functional method is tryRun()
.
- Since:
- 8.0.0
- Author:
- XIMA MEDIA GmbH
-
Method Summary
Modifier and TypeMethodDescriptionstatic IThrowingRunnable
of
(IThrowingRunnable runnable) Returns the given Runnable, for improved variable inference.default void
run()
void
tryRun()
Performs this operation.
-
Method Details
-
tryRun
Performs this operation.- Throws:
Exception
- When this operation fails.
-
run
default void run() -
of
Returns the given Runnable, for improved variable inference. Sometimes you need to create local variables and assign them to a new lambda. This does not work well with variable inference, as Java cannot infer the type of an anonymous lambda. This utility method lets you write slightly more readable code like this:final var supplier = IThrowingRunnable.of(() -> ...);
- Parameters:
runnable
- Runnable to return.- Returns:
- The given consumer.
-