Until now I didn't get my hands dirty on lambda expressions (shame on me, I know
), so this might be a stupid question.
So far I have seen plenty of lambda expressions and I always wonder how you can debug this kind of code. Because these statements mostly are "one line" statements (using method chaining) and you'll probably be interested in the predicate itself and not in the implementation code of e.g. the
filter method.
Reusing the same problem (
print all the odd numbers in a list greater than 15 without any duplicates) from my other
thread. Let's assume there's a bug in our code (just hypothetical of course, we don't write bugs
). How can you debug your code?
With the non-functional solution of your code it's fairly easy: you set a breakpoint on the line with the
if statement and with each iteration you'll be able to inspect variable
i and see if it's added to
set or not:
But with the
Java 8 code, it seems less straightforward.
If I put a breakpoint at the 1st filter statement will it stop with every iteration without going through the
filter method itself. Or do I need to format my code in a specific way to achieve this goal, e.g.:
Probably depends on the
IDE you will be using...
Kind regards,
Roel