Currently, you get into Java lambda expressions and method references.
I want to pass a method with no arguments and no return value as an argument to another method. Here is how I do it:
public void one() { System.out.println("one()"); } public void pass() { run(this::one); } public void run(final Function function) { function.call(); } @FunctionalInterface interface Function { void call(); }
I know that there is a set of predefined functional interfaces in java.util.function , for example, Function<T,R> , but I did not find a single argument without arguments and did not create the result.
java lambda java-8 method-reference
Torsten RΓΆmer Aug 07 '14 at 15:18 2014-08-07 15:18
source share