How do I get IntelliJ to auto-generate a lambda expression as the argument being passed?
What I want:
I have seen the Question How to autocomplete lambdas in IntelliJ IDEA?, but that does not seem to produce my desired result.
As Tagir Valeev already mentioned in his comment, IntelliJ will auto-generate lambda code, but only if your ClickListener
is a (functional) interface.
E.g.:
@FunctionalInterface
interface ClickListener {
void listen();
}
class Clicker {
void addClickListener(ClickListener listener){
// ...
}
}
Then, Intellij suggests upon hitting Ctrl+Shift+Space
Note: As to the @FunctionalInterface
annotation, Jav Doc says
This annotation is not a requirement for the compiler to recognize an interface as a functional interface