Consumer.java official document translation

package java.util.function;

import java.util.Objects;

/**
* Represents an operation that accepts a single argument but does not return a result.
* Unlike other functional interfaces, {@code Consumer} operates through side effects.
*
* <p>This is a <a href="package-summary.html">functional interface</a>
* Its functional method is {@link #accept(Object)}.
*
* @param <T > the type of the input to the operation
*
* @since 1.8
*/
@FunctionalInterface
public interface Consumer<T> {

    /**
     * Execute the operation with the given arguments
     *
     * @param t the input argument
     */
    void accept(T t);

    /**
     * Returns a combined {@code Consumer}, executed serially, followed by {@code after} operations.
     * If an exception is thrown when any operation is performed, it will be passed to the caller of this combined operation.
     * If an exception is thrown while executing this operation, then the {@code after} operation will not be executed.
     *
     * @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); };
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326178080&siteId=291194637