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?
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.
Fortunately, you can assign lambda expressions to variables and reuse them, as you would with objects.
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).
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.
It's in Settings
(shortcut is Strg+Alt+S) underEditor
› Code Style
› Java
› Wrapping and Braces
› Keep when reformatting
› Simple lambdas in one line
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With