Java 8 pass method as parameter
You can also pass lambda like this:
public void pass() {
run(()-> System.out.println("Hello world"));
}
public void run(Runnable function) {
function.run();
}
In this way, you are passing lambda directly as method.
It really does not matter; Runnable
will do too.
Consumer<Void>,
Supplier<Void>,
Function<Void, Void>