java 如何在 IntelliJ IDEA 中自动完成 lambdas?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25182285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to autocomplete lambdas in IntelliJ IDEA?
提问by Tim Büthe
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:
我在 Java 8 中使用 IntelliJ IDEA 13,想知道如何自动完成 lambdas。在 Java 8 之前,我当然使用匿名内部类。我通过键入“new”并点击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.
现在使用 Java 8,我也想生成 lambda,推断参数等等,但我找不到它的自动完成功能。
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.
请注意,上面的示例非常简单,但是当您有多个具有泛型类型的参数时,例如 JavaFX 侦听器等,自动完成功能就派上用场了。
回答by Tim Büthe
In Windows or Linux, it's Ctrl+Space
在 Windows 或 Linux 中,它是Ctrl+Space
In Mac OS, it's Ctrl+Shift+Space
在 Mac OS 中,它是Ctrl+ Shift+Space
回答by sina72
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.
您可以直接输入p = s -> f...
,然后自动完成会提示false
。如果你对 lambda 不确定,你可以从内部类开始,然后把它变成一个 lambda 表达式。
In your example you can press Alt+Enterafterwards, as follows:
在您的示例中,您可以在之后按Alt+ Enter,如下所示:
After completing:
完成后:
After pressing Alt+Enter:
按Alt+ 后Enter:
Result:
结果:
Clicking the small icon at the gutter shows you the Predicate.test
method.
单击装订线处的小图标会显示该Predicate.test
方法。