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); };
    }
}

猜你喜欢

转载自linkinzlz.iteye.com/blog/2397369