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 which may throw.
    • Method Summary

      Modifier and Type Method Description
      static CheckedRunnable of​(CheckedRunnable methodReference)
      Creates a CheckedRunnable.
      void run()
      Performs side-effects.
      default java.lang.Runnable unchecked()
      Returns an unchecked Runnable that will sneaky throw if an exceptions occurs when running the unit of work.
    • Method Detail

      • of

        static CheckedRunnable of​(CheckedRunnable methodReference)
        Creates a CheckedRunnable.
        
         // class Evil { static void sideEffect() { ... } }
         final CheckedRunnable checkedRunnable = CheckedRunnable.of(Evil::sideEffect);
         final Runnable runnable = checkedRunnable.unchecked();
        
         // may or may not perform a side-effect while not throwing
         runnable.run();
        
         // may or may not perform a side-effect while throwing
         runnable.run();
         
        Parameters:
        methodReference - (typically) a method reference, e.g. Type::method
        Returns:
        a new CheckedRunnable
        See Also:
        CheckedFunction1.of(CheckedFunction1)
      • run

        void run()
          throws java.lang.Throwable
        Performs side-effects.
        Throws:
        java.lang.Throwable - if an error occurs
      • unchecked

        default java.lang.Runnable unchecked()
        Returns an unchecked Runnable that will sneaky throw if an exceptions occurs when running the unit of work.
        Returns:
        a new Runnable that throws a Throwable.