Interface ThrowingConsumer<T,​E extends java.lang.Exception>

  • Type Parameters:
    T - the type of the input to the function
    E - the type of the thrown checked exception
    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 ThrowingConsumer<T,​E extends java.lang.Exception>
    Represents a function that accepts one argument and does not return any value; Function might throw a checked exception instance.
    • Method Detail

      • accept

        void accept​(T t)
             throws E extends java.lang.Exception
        Throws:
        E extends java.lang.Exception
      • unchecked

        static <T> java.util.function.Consumer<T> unchecked​(ThrowingConsumer<T,​?> consumer)
      • sneaky

        static <T> java.util.function.Consumer<T> sneaky​(ThrowingConsumer<T,​?> consumer)
        Returns a new BiConsumer instance which rethrows the checked exception using the Sneaky Throws pattern
        Returns:
        BiConsumer instance that rethrows the checked exception using the Sneaky Throws pattern
      • andThenConsume

        default ThrowingConsumer<T,​E> andThenConsume​(ThrowingConsumer<? super T,​? extends E> after)
        Chains given ThrowingConsumer instance
        Parameters:
        after - - consumer that is chained after this instance
        Returns:
        chained Consumer instance
      • asFunction

        default ThrowingFunction<T,​java.lang.Void,​E> asFunction()
        Returns:
        this consumer instance as a Function instance
      • uncheck

        default java.util.function.Consumer<T> uncheck()
        Returns:
        a Consumer instance which wraps thrown checked exception instance into a RuntimeException