IntelliJ:求值lambda表达式会在调试时引发编译错误 [英] IntelliJ: evaluate lambda expression raises an compile error in debugging

查看:143
本文介绍了IntelliJ:求值lambda表达式会在调试时引发编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用Intellij评估代码片段功能来评估包括lambda表达式的代码。但是,Intellij引发了一个错误无法编译目标级别1.8。需要在java版本上运行IDEA至少1.8,目前运行在1.6.0_65-b14-462-11M4609

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());

我的Intellij版本是14.0.3并且根据官方文档,版本14支持lambda表达式评估。

My Intellij version is 14.0.3 and according to official document, version 14 supports lambda expression evaluation.

该功能如何可用?

推荐答案

即使在IntelliJ和Eclipse上应用了上面定义的项目特定设置之后,我仍然失败了!

Even after applying above defined project specific settings on IntelliJ as well as Eclipse, it was still failing for me !

对我有用的是添加带有源和目标的maven插件,并在POM XML中设置1.8:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>com.abc.sparkcore.JavaWordCount</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build> 

这篇关于IntelliJ:求值lambda表达式会在调试时引发编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆