Community
Participate
Working Groups
Consider the following program: ---------------------------------------------------------------- import java.util.stream.IntStream; public class Test { public static void main(String[] args) { for (int i = 0; i < 3; i++) System.out.println(i); IntStream.range(0, 3).forEach(i -> System.out.println(i)); } } ---------------------------------------------------------------- It is a common thing to add curly braces where there was a single statement before, and then hit enter. Adding curly braces: ---------------------------------------------------------------- for (int i = 0; i < 3; i++) { System.out.println(i); IntStream.range(0, 3).forEach(i -> { System.out.println(i)); ---------------------------------------------------------------- Hitting enter: ---------------------------------------------------------------- for (int i = 0; i < 3; i++) { System.out.println(i); } IntStream.range(0, 3).forEach(i -> { }System.out.println(i)); ---------------------------------------------------------------- While the for loop correctly enclosed the println statement in the curly braces, the lambda expression got broken. The expected behaviour would be this (note also the added ";") ---------------------------------------------------------------- IntStream.range(0, 3).forEach(i -> { System.out.println(i); }); ----------------------------------------------------------------
It is not sufficient to add the braces and semicolon correctly. For example: IntStream.range(0, 3).mapToObj(i -> Integer.toHexString(i)); should result in: IntStream.range(0, 3).mapToObj(i -> { return Integer.toHexString(i); }); To get the expected result, you should use the quick assist "Change body expression to block" at lambda expression. This bug can be kept to just move the lambda body within braces when Enter is pressed.
You're right, it's not sufficient to just move the body and add semicolons. I only documented the case of a void-compatible lambda expression (e.g. a Consumer). But since the intent of hitting enter after those initial curly braces is rather clear, I still vote for handling the action just the same as the quick assist "Change body expression to block". It would be a very convenient action, rather than hitting the menu and making a choice among several options...
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
> This bug can be kept to just move the lambda body within braces when Enter is pressed. But then it got auto-closed (which I still don't find a very good practice). I'd still love to see this fixed.