How to autocomplete lambdas in IntelliJ IDEA?

两盒软妹~` 提交于 2019-12-31 09:16:50

问题


I'm using IntelliJ IDEA 13 with Java 8 and wonder how to autocomplete lambdas. Before Java 8 I used anonymous inner classes of course. I auto completed by typing "new" and hitting Ctrl+Space:

and choosing the first option.

Now with Java 8 I want to generate lambdas as well, inferring parameters and all, but I can't find autocompletion for it.

Note, this above example is quite easy, but when you have multiple parameters with generic types, e.g. JavaFX Listeners and the like, autocompletion comes in handy.


回答1:


In Windows or Linux, it’s Ctrl+Space

In Mac OS, it’s Ctrl+Shift+Space




回答2:


You can just type p = s -> f..., autocompletion will then suggest false. If you're not sure about lambda, you can start with the inner class, and then turn it into a lambda expression.

In your example you can press Alt+Enter afterwards, as follows:

After completing:

After pressing Alt+Enter:

Result:

Clicking the small icon at the gutter shows you the Predicate.test method.



来源:https://stackoverflow.com/questions/25182285/how-to-autocomplete-lambdas-in-intellij-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!