- Type Parameters:
T- the type of argument consumed
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
ThrowingConsumeris a functional interface that can be used to implement any generic block of code that consumes an argument and potentially throws a
ThrowingConsumerinterface is similar to
Consumer, except that a
ThrowingConsumercan throw any kind of exception, including checked exceptions.
Rationale for throwing
Although Java applications typically throw exceptions that are instances of
AssertionError(in testing scenarios), there may be use cases where a
ThrowingConsumerneeds to explicitly throw a
Throwable. In order to support such specialized use cases,
accept(T)is declared to throw
void accept(T t) throws java.lang.ThrowableConsume the supplied argument, potentially throwing an exception.
t- the argument to consume