mjs
mjs

Reputation: 22357

Configure Intellij for Java 8 lambda defaults

Is it possible to have intellij always declare lambdas in a certain way.

For instance, sometime intellij will refactor a lambda into:

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.

Can this be done?

Upvotes: 2

Views: 17315

Answers (1)

kuporific
kuporific

Reputation: 10322

This is not possible in IntelliJ 13 (but maybe in 14?). Your workaround, of course, is the refactoring options (Ctrl+Enter) "Expand Lambda expression body to {...}".

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.

Upvotes: 2

Related Questions