I'd like to evaluate code including lambda expression with Intellij 'Evaluate Code Fragment' feature. But then, Intellij raises an error Unable to compile for target level 1.8. Need to run IDEA on java version at least 1.8, currently running on 1.6.0_65-b14-462-11M4609
The evaluating code is very simple as below.
Set<Integer> set = new HashSet<>();
set.add(1);
set.stream().map(v->v).collect(Collectors.toSet());
My Intellij version is 14.0.3 and according to official document, version 14 supports lambda expression evaluation.
How can the feature be available?
You can use the Run to cursor function on a lambda expression as well. You can use Ctrl+F8 to add a breakpoint. Then the lambda expression that the cursor is placed on will be selected in the list. Pressing Ctrl+F8 again will complete creating a breakpoint on the selected lambda.
Evaluate a complex expression in the editorClick Run | Debugging Actions | Quick Evaluate Expression Ctrl+Alt+F8 .
We can use different IDE's like Netbeans, IntelliJ, and Eclipse to debug the lambda expressions in Java. It is always possible to create multi-line lambda expressions and use print statements to display the values of a variable. The debugger can also provide additional information about the state of a java program.
Alt + F8 is the shortcut for evaluation of an expression or variable.
Putting together the comments from adrian lange and Bohuslav Burghardt, either upgrade to the latest IntelliJ 14.1 which comes bundled with Java 1.8, or switch your current IntelliJ to use Java 1.8. See bug IDEA-132099.
To switch to Java 1.8:
You can switch runtime version of JDK:
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