I wrote the following lambda expression
int size = ((List<?>) receipt.getPositions().stream().filter(item -> true).collect(Collectors.toList())).size()
The variable size
is computed correctly!
But when I try to inspect it (Ctrl+Shift+I) or try to see the result of the expression in Eclipse expressions view, I get the following error:
"Lambda expressions cannot be used in an evaluation expression"
Are there any other opportunities to see the result of such an expression instead of storing it to a variable?
P.S.: I am using Java 8 and Eclipse neon.2
A simple solution for this, that works is to convert your lambda in an anonymous class creation. Creating a variable of the interface needed, you'll get a debuggable expression.
Predicate<Object> predicate = new Predicate<Object>() {
@Override
public boolean test(Object item) {
return true;
}
};
int size = ((List<?>) receipt.getPositions().stream().filter(predicate).collect(Collectors.toList())).size();
Now, if you're standing at the line "int size = ..." while debugging, you can view the result of following:
((List<?>) receipt.getPositions().stream().filter(predicate).collect(Collectors.toList())).size()
I hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With