Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty lambda expression on same line

Per default, IntelliJ 15.0.3 puts the closing brace of an empty lambda expression on the next line when reformatting the code.

Consumer<String> myFunc= aString -> {
};

In my opinion this is slightly detrimental to code readability and I want to keep the empty lambda expression on the same line:

Consumer<String> myFunc= aString -> {};

Where can I find the setting to change this?

like image 604
Matthias Braun Avatar asked Feb 04 '16 11:02

Matthias Braun


People also ask

Can lambda expression have empty body?

The body of a lambda expression can contain zero, one or more statements. When there is a single statement curly brackets are not mandatory and the return type of the anonymous function is the same as that of the body expression.

Can we reuse lambda expression?

Fortunately, you can assign lambda expressions to variables and reuse them, as you would with objects.

Is lambda expression faster than forEach?

Here I/O operation ( println ) is much slower than all possible overhead of calling lambda or creating an iterator. In general forEach might be slightly faster as it does everything inside the single method without creating the Iterator and calling hasNext and next (which is implicitly done by for-each loop).

What are the three parts of a lambda expression?

A lambda in Java essentially consists of three parts: a parenthesized set of parameters, an arrow, and then a body, which can either be a single expression or a block of Java code.


1 Answers

It's in Settings (shortcut is Strg+Alt+S) underEditorCode StyleJavaWrapping and BracesKeep when reformattingSimple lambdas in one line:

intellij settings

like image 74
Matthias Braun Avatar answered Oct 09 '22 00:10

Matthias Braun