src/share/classes/java/util/function/Consumer.java
Print this page
rev 7675 : 8019840: Spec updates for java.util.function
Reviewed-by: mduigou
Contributed-by: brian.goetz@oracle.com
@@ -25,43 +25,43 @@
package java.util.function;
import java.util.Objects;
/**
- * An operation which accepts a single input argument and returns no result.
- * Unlike most other functional interfaces, {@code Consumer} is expected to
- * operate via side-effects.
+ * Represents an operation that accepts a single input argument and returns no
+ * result. Unlike most other functional interfaces, {@code Consumer} is expected
+ * to operate via side-effects.
*
- * @param <T> The type of input objects to {@code accept}
+ * <p>This is a <a href="package-summary.html">functional interface</a>
+ * whose functional method is {@link #accept(Object)}.
+ *
+ * @param <T> the type of the input to the operation
*
* @since 1.8
*/
@FunctionalInterface
public interface Consumer<T> {
/**
- * Accept an input value.
+ * Performs this operation on the given argument.
*
- * @param t the input object
+ * @param t the input argument
*/
void accept(T t);
/**
- * Returns a {@code Consumer} which performs, in sequence, the operation
- * represented by this object followed by the operation represented by
- * the other {@code Consumer}.
- *
- * <p>Any exceptions thrown by either {@code accept} method are relayed
- * to the caller; if performing this operation throws an exception, the
- * other operation will not be performed.
+ * 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 other a Consumer which will be chained after this Consumer
- * @return a Consumer which performs in sequence the {@code accept} method
- * of this Consumer and the {@code accept} method of the specified Consumer
- * operation
- * @throws NullPointerException if other is null
+ * @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> chain(Consumer<? super T> other) {
- Objects.requireNonNull(other);
- return (T t) -> { accept(t); other.accept(t); };
+ default Consumer<T> andThen(Consumer<? super T> after) {
+ Objects.requireNonNull(after);
+ return (T t) -> { accept(t); after.accept(t); };
}
}