Created
July 13, 2019 20:14
-
-
Save pellse/2ad2bca307b788023e1c6fecb725dc56 to your computer and use it in GitHub Desktop.
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
import org.junit.Test; | |
public class MethodReferenceTests { | |
@Test | |
public void testMethodReferenceVsLambda () { | |
Runnable r1 = () -> new Counter().print(); | |
Runnable r2 = new Counter()::print; | |
r1.run(); | |
r1.run(); | |
r2.run(); | |
r2.run(); | |
} | |
} | |
class Counter { | |
private static int count; | |
private int myCount; | |
Counter() { | |
this.myCount = count++; | |
} | |
void print() { | |
System.out.println("myCount = " + this.myCount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment