Interface FailableConsumer<T,​E extends Exception>

  • Type Parameters:
    T - The type of the data being consumed
    E - The exception type
    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 FailableConsumer<T,​E extends Exception>
    A consumer that may fail with a checked exception during the execution of the accept(..) method.
    Author:
    Eyal Schneider
    • Method Detail

      • accept

        void accept​(T t)
             throws E extends Exception
        Performs this operation on the given argument.
        Parameters:
        t - the input argument
        Throws:
        E - in case of an error during the data consumption
        E extends Exception
      • andThen

        default FailableConsumer<T,​E> andThen​(FailableConsumer<? super T,​? extends E> after)
        Similar to andThen method of Consumer
        Parameters:
        after - the operation to perform after this operation
        Returns:
        a composed FailableConsumer that performs in sequence this operation followed by the after operation
      • fromConsumer

        static <T,​E extends ExceptionFailableConsumer<T,​E> fromConsumer​(Consumer<T> consumer)
        Utility method for wrapping a consumer with a failable consumer
        Type Parameters:
        T - The type of the data being consumed
        E - The exception type
        Parameters:
        consumer - The consumer to wrap
        Returns:
        The failable consumer (which effectively never throws checked exceptions)