This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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