Consumer.java官方文档翻译

package java.util.function;

import java.util.Objects;

/**
* 表示接收单个参数但是不返回结果的操作。
* 与其它函数式接口不同的是,{@code Consumer} 通过副作用进行操作。
*
* <p>这是一个 <a href="package-summary.html">函数式 接口</a>
* 它的函数式方法是 {@link #accept(Object)}.
*
* @param <T> the type of the input to the operation
*
* @since 1.8
*/
@FunctionalInterface
public interface Consumer<T> {

/**
* 通过给定的参数执行操作
*
* @param t the input argument
*/
void accept(T t);

/**
* 返回一个组合的 {@code Consumer},串行执行,后面跟着{@code after}操作。
* 如果执行任何操作时都抛出异常,将会传递给这个组合操作的调用者。
* 如果在执行这个操作时抛出一个异常,那么{@code after}操作将不会被执行。
*
* @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); };
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值