如何使用 Eclipse 在 Java 8 中调试 lambda 表达式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39637183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:17:27  来源:igfitidea点击:

How to debug lambda expression in Java 8 using Eclipse?

eclipsedebugginglambdajava-8

提问by IamVickyAV

I am trying to debug a simple Java application which is using Lambda Expression. I am not able to debug Lambda Expression using normal Eclipse debugger.

我正在尝试调试一个使用 Lambda 表达式的简单 Java 应用程序。我无法使用普通 Eclipse 调试器调试 Lambda 表达式。

采纳答案by José Domingo Balderas

It's late answer but hope it is useful for someone. I use this https://stackoverflow.com/a/24542150/10605477but sometimes when code is a bit messy or I can't get data I just break the code and insert peek.

这是迟到的答案,但希望它对某人有用。我使用这个https://stackoverflow.com/a/24542150/10605477但有时当代码有点乱或我无法获取数据时,我只是破坏代码并插入 peek。

protected Optional<Name> get(String username) {
    return profileDao.getProfiles()             
            .stream()
            .filter(profile -> 
                    profile.getUserName().equals(username))
            .peek(data -> System.out.println(data))
            .findFirst();
}

回答by mrt181

You can transform the expressions into statements.

您可以将表达式转换为语句。

List<String> list = new ArrayList<>();

// expression
boolean allMatch1 = list.stream().allMatch(s -> s.contains("Hello"));
// statement
boolean allMatch2 = list.stream().allMatch(s -> {
  return s.contains("Hello");
});

You can now set the break-point on the return s.contains("Hello");line

您现在可以return s.contains("Hello");在行上设置断点