Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@FunctionalInterface
public Consumer<T> {
void accept(T t);
}
// Hoặc khai báo bằng lamba
Consumer<T> consumer = p -> System.out.println(p);
// Hoặc dùng method reference
Consumer<T> consumer = System.out::println;
// Hoặc phức tạp hơn
@FunctionalInterface
public Consumer<T> {
void accept(T t);
default Consumer<T> andThen(Consumer<? super T> after) {
Object.requireNonNull(after);
return (T t) -> {
accept(t);
after.accept(t);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment