Skip to content

Instantly share code, notes, and snippets.

@pellse
Created July 13, 2019 20:14
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 pellse/2ad2bca307b788023e1c6fecb725dc56 to your computer and use it in GitHub Desktop.
Save pellse/2ad2bca307b788023e1c6fecb725dc56 to your computer and use it in GitHub Desktop.
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