一、问题展示
二、问题原因
IDEA工具如果不配置,默认会将源代码JDK版本设置为1.5,目标代码JDK版本设置为1.5。
三、解决方法
第一步,配置项目POM文件,新增:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
第二步,配置本地Maven的setting.xml文件,新增:
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
第四步,打开如下路径:
File>Project Structure>Project Settings>Modules>Sources
修改languages Level为JDK8,如下图所示:
第五步,打开如下路径:
File>Settings>Build,Execution,Deployment>Compiler>Java Compiler
分别修改:Project bytecode version和Target bytecode version,都修改为8,如下图所示:
四、总结
通过以上步骤操作完,项目再更新就不会出现开始的错误了,实测有效,多年的强迫症治好了。
工作中难免会遇到这样、那样的问题,年纪大了,记不住。通过网上各种搜索找方法解决了,就记一下,希望对下一位坑友也有所帮助吧。