Skip to content

Instantly share code, notes, and snippets.

@SungjinYoo
Created November 16, 2018 13:30
Show Gist options
  • Save SungjinYoo/5ec8edd892cae8ec1c7103cd9b529978 to your computer and use it in GitHub Desktop.
Save SungjinYoo/5ec8edd892cae8ec1c7103cd9b529978 to your computer and use it in GitHub Desktop.
@FunctionalInterface
interface Printer {
void print(String value);
}
class TextPrinter implements Printer {
void print(String value) {
System.out.println(value);
}
}
Printer printer = new TextPrinter();
printer.print("Hi"); // prints out "Hi"
printer = printer::print;
printer.print("Hi"); // also prints out "Hi"
Printer printer = (value) -> {
System.out.println(value);
}
printer.print("Hi"); // prints out "Hi"
printer = System.out::println;
printer.print("Hi"); // also prints out "Hi"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment