Let\'s say I have the following functional interface in Java 8:
interface Action {
U execute(T t);
}
And for some cases I ne
Add a static method inside your functional interface
package example;
interface Action {
U execute(T t);
static Action invoke(Runnable runnable){
return (v) -> {
runnable.run();
return null;
};
}
}
public class Lambda {
public static void main(String[] args) {
Action a = Action.invoke(() -> System.out.println("Do nothing!"));
Void t = null;
a.execute(t);
}
}
Output
Do nothing!