How to debug lambda expression in Java 8 using Eclipse?

16,438

Solution 1

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

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

Solution 2

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

Share:
16,438
IamVickyAV
Author by

IamVickyAV

Updated on June 09, 2022

Comments

  • IamVickyAV
    IamVickyAV almost 2 years

    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.

  • Holger
    Holger over 7 years
    There is no need to transform the expression to a statement. Just inserting a line break after -> is sufficient.