Skip to content

Instantly share code, notes, and snippets.

@itang
Created June 15, 2016 03:49
Show Gist options
  • Save itang/61e1b3bc740093d6db516b39fa7e0910 to your computer and use it in GitHub Desktop.
Save itang/61e1b3bc740093d6db516b39fa7e0910 to your computer and use it in GitHub Desktop.
interface Nameable {
String getName();
}
public class Test {
public static void main(String[] args) {
Nameable nameable1 = "String"::toString;
hello(nameable1);
hello("String"::toString);
Nameable nameable2 = () -> "yourname";
hello(nameable2);
hello(() -> "yoruname2");
// hello(() -> 111 ); // compile error
}
public static void hello(Nameable n) {
System.out.println("hello " + n.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment