错误描述
在用IDEA编译别人的项目的时候遇到下面的错误:
java: try-with-resources is not supported in -source 1.6 (use -source 7 or higher to enable try-with-resources)
按词面理解是编译器抱怨说 source 1.6 不支持 try-with-resources 特性, 需要启用该特性要设置 source 1.7 或更高的版本
解决办法
- 设置当前模块的 Source Language Level:
File -> Project Structure -> Modules -> Sources -> Language Level
选择 8 - Lambdas, type annotations etc.
设置完成之后没有了之前的那个错误了,但是出现了另一个错误:
Error:java: javacTask: source release 1.8 requires target release 1.8
编译器又抱怨说虽然source已经是1.8了,但同时target也要设置为1.8
- 设置当前模块的 Target Language Level:
File -> Settings -> File | Settings | Build, Execution, Deployment -> Compiler -> Java Compiler -> Per-module bytecode version -> Target bytecode version
选择 1.8
再重新编译,OK一切正常了~