Java 8: Formatting lambda with newlines and indentation

后端 未结 9 1119
[愿得一人]
[愿得一人] 2020-12-12 23:46

What I would like to achieve with lambda indentation is the following:

Multi-line statement:

String[] ppl = new String[] { \"Karen (F)\", \"Kevin (M)         


        
9条回答
  •  醉梦人生
    2020-12-12 23:56

    If you don’t already have a custom Eclipse formatter:

    Eclipse preferences Java > Code Style > Formatter New Enter a name Click ok Control line breaks

    Edit the profile Line wrapping tab Check “Never join already wrapped lines”

    It will end up like this

        String phrase = employeeList
                .stream()
                .filter(p -> p.getAge() >= 33)
                .map(p -> p.getFirstName())
                .collect(Collectors.joining(" and ", "In Germany ", " are of legal age."));
    

    Need to type every . start in the next line

    credits - https://www.selikoff.net/2017/07/02/eclipse-and-line-wrapping/

提交回复
热议问题