Let\'s say I have the following functional interface in Java 8:
interface Action {
U execute(T t);
}
And for some cases I ne
The lambda:
() -> { System.out.println("Do nothing!"); };
actually represents an implementation for an interface like:
public interface Something {
void action();
}
which is completely different than the one you've defined. That's why you get an error.
Since you can't extend your @FunctionalInterface
, nor introduce a brand new one, then I think you don't have much options. You can use the Optional
interfaces to denote that some of the values (return type or method parameter) is missing, though. However, this won't make the lambda body simpler.