Interface ThrowingConsumer<T>
- Type Parameters:
T- type of the input element
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
This functional interface allows to not catch an Exception in a
lambda expression : use it at your own risk, the exception
becomes unchecked.
It is recommended to use it only in a method that can throw the
Exception type that is unchecked. So the exception can be
checked when using the method.
Source : http://4comprehension.com/sneakily-throwing-exceptions-in-lambda-expressions-in-java/
-
Method Summary
Modifier and TypeMethodDescriptionvoidRedefine the accept method to be able to declare that an exception is thrownstatic <T> Consumer<T> unchecked(ThrowingConsumer<T> c) Wraps a throwing consumer into a standard consumer by rethrowing exceptions unchecked.
-
Method Details
-
accept
-
unchecked
Wraps a throwing consumer into a standard consumer by rethrowing exceptions unchecked.- Type Parameters:
T- type of the input element- Parameters:
c- the consumer to call- Returns:
- the consumer result
-