OnJava8-Examples/innerclasses/RunnableMethodReference.java
2015-05-27 18:27:06 -07:00

32 lines
753 B
Java

//: innerclasses/RunnableMethodReference.java
// Demonstrates method references
import static net.mindview.util.Print.*;
class External {
static void go() { print("External.go()"); }
}
public class RunnableMethodReference {
Runnable robject, rstatic, rexstatic;
void f() { print("f()"); }
static void g() { print("g()"); }
public void assign() {
robject = this::f;
rstatic = RunnableMethodReference::g;
rexstatic = External::go;
}
public void call() {
robject.run();
rstatic.run();
rexstatic.run();
}
public static void main(String[] args) {
RunnableMethodReference rmr =
new RunnableMethodReference();
rmr.assign();
rmr.call();
rmr.robject = rmr::f;
rmr.robject.run();
}
} ///:~