IamVickyAV
IamVickyAV

Reputation: 1555

How to debug lambda expression in Java 8 using Eclipse?

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.

Upvotes: 10

Views: 22111

Answers (2)

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();
}

Upvotes: 3

mrt181
mrt181

Reputation: 5316

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

Upvotes: 2

Related Questions