T
- the type of the input to the operation@FunctionalInterface public interface ThrowingConsumer<T> extends Consumer<T>
ThrowingConsumer
is
expected to operate via side-effects.
ThrowingConsumer
s can throw any kind of Exception
. When used
as Consumer
exceptions are hidden from compiler.
This is a functional interface whose
functional method is acceptThrowing(Object)
.
Modifier and Type | Method and Description |
---|---|
default void |
accept(T value)
Performs this operation on the given argument, allow throwing any kind of
Exception . |
void |
acceptThrowing(T value)
Performs this operation on the given argument, allow throwing any kind of
Exception . |
static <T> Consumer<T> |
throwing(ThrowingConsumer<T> consumer)
Short-hand method to cast any
ThrowingConsumer as Consumer . |
static <T> Consumer<T> throwing(ThrowingConsumer<T> consumer)
ThrowingConsumer
as Consumer
.T
- the type of the input to the operationconsumer
- throwing consumerdefault void accept(@Nullable T value)
Exception
.
As this hides exceptions from the compiler, the calling method should either:
throws
statement for the hidden exceptions
catch
@throws
.
accept
in interface Consumer<T>
value
- the input argumentSneakyException
- hidden exceptionsCopyright © 2025. All rights reserved.