Skip to content

Instantly share code, notes, and snippets.

@codeaholicguy
Last active December 16, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeaholicguy/be649bd27e78df4b0de8 to your computer and use it in GitHub Desktop.
Save codeaholicguy/be649bd27e78df4b0de8 to your computer and use it in GitHub Desktop.
@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