Package de.xima.fc.interfaces
Interface IThrowingConsumer<T>
-
- Type Parameters:
T
- the type of the input to the operation
- All Superinterfaces:
Consumer<T>
- 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 IThrowingConsumer<T> extends Consumer<T>
AConsumer
that may throw a checked exception.Represents an operation that accepts a single input argument and returns no result. Unlike most other functional interfaces,
Consumer
is expected to operate via side-effects.This is a
functional interface
whose functional method istryAccept(Object)
.- Since:
- 8.0.0
- Author:
- XIMA MEDIA GmbH
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
accept(T t)
static <T> IThrowingConsumer<T>
of(IThrowingConsumer<T> consumer)
Returns the given consumer, for improved variable inference.static <T> IThrowingConsumer<T>
throwingConsumer(IThrowingConsumer<T> consumer)
Returns the given consumer, for improved variable inference.void
tryAccept(T t)
Performs this operation on the given argument.
-
-
-
Method Detail
-
tryAccept
void tryAccept(T t) throws Exception
Performs this operation on the given argument.- Parameters:
t
- the input argument- Throws:
Exception
- When this operation fails.
-
of
static <T> IThrowingConsumer<T> of(IThrowingConsumer<T> consumer)
Returns the given consumer, for improved variable inference. Sometimes you need to create local variables and assign them to a new lambda. This does not work well with variable inference, as Java cannot infer the type of an anonymous lambda. This utility method lets you write slightly more readable code like this:final var supplier = IThrowingConsumer.of(() -> ...);
- Type Parameters:
T
- the type of the input to the operation- Parameters:
consumer
- Consumer to return.- Returns:
- The given consumer.
-
throwingConsumer
static <T> IThrowingConsumer<T> throwingConsumer(IThrowingConsumer<T> consumer)
Returns the given consumer, for improved variable inference. Sometimes you need to create local variables and assign them to a new lambda. This does not work well with variable inference, as Java cannot infer the type of an anonymous lambda. This utility method lets you write slightly more readable code like this:final var supplier = throwingConsumer(() -> ...);
- Type Parameters:
T
- the type of the input to the operation- Parameters:
consumer
- Consumer to return.- Returns:
- The given consumer.
-
-