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 CheckedRunnable
    A Runnable that is allowed to throw checked exceptions.
    • Method Detail

      • of

        static CheckedRunnable of​(@NonNull CheckedRunnable methodReference)
        Creates a CheckedRunnable from 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 CheckedRunnable wrapping 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 unchecked Runnable that sneakily throws any exception encountered during execution of this unit of work.
        Returns:
        a Runnable that may throw any Throwable without declaring it