Java / Eclipse: "Lambda expressions cannot be used in an evaluation expression"
I wrote the following lambda expression
int size = ((List<?>) receipt.getPositions().stream().filter(item -> true).collect(Collectors.toList())).size() The variable size calculated correctly!
But when I try to check it ( Ctrl + Shift + I ) or try to see the result of the expression in the expression of the Eclipse expressions, I get the following error:
"Lambda expressions cannot be used in a value expression"
Are there other ways to see the result of such an expression instead of storing it in a variable?
PS: I use Java 8 and Eclipse neon. 2
A simple solution to this is to convert your lambda to create an anonymous class. By creating a variable of the required interface, you get a debug 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 are standing in the line "int size = ..." during debugging, you can view the result of the following:
((List<?>) receipt.getPositions().stream().filter(predicate).collect(Collectors.toList())).size() Hope this helps :)
