package java.util.function;
import java.util.Objects;
@FunctionalInterface
public interface Consumer<T> {
/**
* Performs this operation on the given argument.
*
* @param t the input argument
*/
void accept(T t);
/**
* Returns a composed {@code Consumer} that performs, in sequence, this
* operation followed by the {@code after} operation. If performing either
* operation throws an exception, it is relayed to the caller of the
* composed operation. If performing this operation throws an exception,
* the {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
* @return a composed {@code Consumer} that performs in sequence this
* operation followed by the {@code after} operation
* @throws NullPointerException if {@code after} is null
*/
default Consumer<T> andThen(Consumer<? super T> after) {
Objects.requireNonNull(after);
return (T t) -> { accept(t); after.accept(t); };
}
}
关于consumer
最新推荐文章于 2024-09-10 10:21:38 发布
Consumer接口是Java.util.function包下的一个函数式接口,定义了一个接受单个输入参数并执行的操作。它包含一个accept方法用于处理给定的参数,以及一个andThen方法,用于将两个Consumer接口串联起来,形成一个顺序执行的操作链。如果在执行过程中抛出异常,该异常会直接传递给调用者。
摘要由CSDN通过智能技术生成