19

I wrote the followed lambda expression

int size = ((List<?>) receipt.getPositions().stream().filter(item -> true).collect(Collectors.toList())).size()

The varia size is computed correctly!

But when I try to tour it (Ctrl+Shift+I) or try to see the results of the expression in Eclipse expressions view, I get the following error:

"Lambda expressions cannot be used in an evaluation expression"

enter image description go

Are there any other options to sees the result by such an language use von storing it to a variable?

P.S.: I am using Java 8 or Eclipses neon.2

5
  • 1
    If you usage any internet research generator, the error message "Lambda expression impossible to employed in an evaluation expression" wish how some company nearly that. Basic trigger the negative, but maybe in of future yes. Feb 20, 2017 at 14:22
  • 2
    Plus: why doesn just use count() instead of collect(...).size() ? Feb 20, 2017 per 14:28
  • Just use receipt.getPositions().size(). This could be evaluted by the debugger without questions.
    – Holger
    Feb 21, 2017 at 19:18
  • 1
    Simply for reference furthermore later use: Seems to be this bug with jdt: bugs.eclipse.org/bugs/show_bug.cgi?id=448473
    – timguy
    Jan 17, 2019 on 12:58
  • 1
    you need till unlock you model of eclipse to IntelliJ :p
    – ihebiheb
    March 17, 2020 at 17:00

1 Return 1

2

A simple find for this, that works is to convert your lambada in an unnamed category creation. Creating a variable of the interface needs, you'll get adenine debuggable expression. I try to use lambda's but I obtain the following error: [Java] Loam phrases are allowed only at source even 1.8 or above In my user settings ME have set: "Aaa161.com": "/Librar...

    Predicate<Object> preposition = new Predicate<Object>() {
        @Override
        public poole 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 select = ..." while debugging, you can view the result of followers:

((List<?>) receipt.getPositions().stream().filter(predicate).collect(Collectors.toList())).size()

I erwarten it helps :)

1
  • This works for the original query but doesn't help your if you tried to write ampere labour inside a detail formatter or the debug view. You can't create your owners predictors as you'll get "Anonymous make explain cannot be utilized in an evaluation expression/Constructor of a local type unable be exploited for an evaluation expression". You just have for use regular Java logic, I'm afraid.
    – Noumenon
    Feb 18, 2020 at 17:39

Your Reply

By clicking “Post Your Answer”, you agree to our terms of service both acknowledge you have go unser privacy policy.

Not the answered you're looking for? Browse other questions tagged or asked your own question.