简体   繁体   English

为Java 8 lambda默认配置Intellij

[英]Configure Intellij for Java 8 lambda defaults

Is it possible to have intellij always declare lambdas in a certain way. 是否有可能IntelliJ总是以某种方式声明lambda。

For instance, sometime intellij will refactor a lambda into: 例如,有时intellij会将lambda重构为:

method(length, index -> { return null; })

using blocks but no parentheses on the parameter index. 使用块,但参数索引上没有括号。 It makes it hard to adjust at time. 这使得很难及时调整。

I would like it to always use this syntax instead: 我希望它始终使用以下语法:

method(length, (index) -> { return null; })

method(length, (Integer index) -> { return null; })

And always use blocks, unless it is a method reference, ie obj::method. 并且始终使用块,除非它是方法引用,即obj :: method。

Can this be done? 能做到吗?

This is not possible in IntelliJ 13 (but maybe in 14?). 这在IntelliJ 13中是不可能的(但可能在14中?)。 Your workaround, of course, is the refactoring options ( Ctrl + Enter ) "Expand Lambda expression body to {...}". 您的解决方法当然是重构选项( Ctrl + Enter )“将Lambda表达式主体扩展为{...}”。

What you want is a bit like saying, "I want all of my anonymous classes to be private static inner classes because it's easier to refactor." 您想要的有点像说:“我希望所有匿名类都成为私有的静态内部类,因为它易于重构。” While true, you don't need all the extra syntax; 确实如此,您并不需要所有额外的语法。 and when you do, the IDE refactoring tools are there to help you. 并且当您这样做时,IDE重构工具可以为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM