Created
October 14, 2018 08:48
-
-
Save holograph/7ee22eb1c1cad61b5d3957673b1dc3d9 to your computer and use it in GitHub Desktop.
Showcasing Java method references
This file contains hidden or 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
import java.util.function.Supplier; | |
class A { | |
static int staticSupplier() { return 5; } | |
int instanceSupplier() { return 10; } | |
static void printOut(Supplier<Integer> supplier) { | |
System.out.println(supplier.get()); | |
} | |
public static void main(String[] args) { | |
A a = new A(); | |
printOut(A::staticSupplier); | |
printOut(a::instanceSupplier); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment