Interface CheckedConsumer<T>
- Type Parameters:
T- the value type supplied to this consumer.
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A consumer that may throw, equivalent to Consumer.
-
Method Summary
Modifier and TypeMethodDescriptionvoidPerforms side-effects.default CheckedConsumer<T> andThen(CheckedConsumer<? super T> after) Returns a chainedCheckedConsumerthat first executesthis.accept(t)and thenafter.accept(t), for a giventof typeT.static <T> CheckedConsumer<T> of(CheckedConsumer<T> methodReference) Creates aCheckedConsumer.Returns an uncheckedConsumerthat will sneaky throw if an exceptions occurs when accepting a value.
-
Method Details
-
of
Creates aCheckedConsumer.final CheckedConsumer<Value> checkedConsumer = CheckedConsumer.of(Value::stdout); final Consumer<Value> consumer = checkedConsumer.unchecked(); // prints "Hi" on the console consumer.accept(CharSeq.of("Hi!")); // throws consumer.accept(null);- Type Parameters:
T- type of values that are accepted by the consumer- Parameters:
methodReference- (typically) a method reference, e.g.Type::method- Returns:
- a new
CheckedConsumer - See Also:
-
accept
-
andThen
Returns a chainedCheckedConsumerthat first executesthis.accept(t)and thenafter.accept(t), for a giventof typeT.- Parameters:
after- the action that will be executed after this action- Returns:
- a new
CheckedConsumerthat chainsthisandafter - Throws:
NullPointerException- ifafteris null
-
unchecked
-