问题:在idea中遇到如下问题
//-source 1.5 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
Diamond types are not supported at language level '5'
//-source 1.5 中不支持 lambda 表达式(请使用 -source 8 或更高版本以启用 lambda 表达式)
Lambda expressions are not supported at language level '5'
解决方法:
1、File -> Project Structure -> Modules -> Sources -> Language level -> 如果是jdk1.8 就是 8 - Lambdas,type annotations etc
注:这样idea就没有报错了,但是编译的时候还会报错Error:java: Compilation failed: internal java compiler error
2、pom文件加入,指定maven-compiler-plugin
的版本号,尤其是-source
和-target
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
maven-compiler-plugin最新的是3.8.1
,里面写了默认的-source
和-target
是1.6,强烈建议更改-source
和-target
的默认值
![](https://img.haomeiwen.com/i2802381/4ae1b33a68519d0a.png)
网友评论