티스토리 뷰

JAVA

Consumer

kkoon9 2022. 2. 4. 21:08

함수형 인터페이스입니다.

단일 입력 인수를 수락하고 결과를 반환하지 않는 작업을 나타냅니다.

대부분의 다른 함수형 인터페이스와 달리 Consumer는 사이드 이팩트을 통해 작동할 것으로 예상됩니다.

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

 

void accept(T t);

지정된 인수에 대해 이 작업을 수행합니다.

default Consumer<T> andThen(Consumer<? super T> after)

이 작업 다음에 after 연산을 순서대로 수행하는 합성된 Consumer를 반환합니다.

두 작업 중 하나를 수행하면 예외가 발생하는 경우 합성 작업의 호출자에게 전달됩니다.

이 작업을 수행하면 예외가 발생하면 애프터 작업이 수행되지 않습니다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함