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.

    @FunctionalInterface
    public interface IThrowingRunnable
    extends Runnable
    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 Detail

      • tryRun

        void tryRun()
             throws Exception
        Performs this operation.
        Throws:
        Exception - When this operation fails.
      • run

        default void run()
        Specified by:
        run in interface Runnable
      • of

        static IThrowingRunnable of​(IThrowingRunnable runnable)
        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.