IntelliJ错误 - 在-source 1.6错误中不支持java:try-with-resources。即使在项目设置中,也选择了1.7 JDK

IntelliJ错误 - 在-source 1.6错误中不支持java:try-with-resources。即使在项目设置中,也选择了1.7 JDK

问题描述:

在文件 - >项目结构 - > SDKs我有1.7 jdk,但我仍然收到此错误:

Under File -> Project Structure -> SDKs i have 1.7 jdk but i still get this error:

added.java:不支持try-with-resources in -source 1.6
(使用-source 7或更高版本来启用资源试用)

added.java: try-with-resources is not supported in -source 1.6 (use -source 7 or higher to enable try-with-resources)

我已重新启动IDE但无效

I have restarted IDE but to no avail

较新的JVM允许您使用较低JVM版本的编译器版本编译代码。例如,JDK 1.7允许您使用1.5编译器编译代码。

Newer JVMs allow you to compile your code using compiler versions of lower JVM versions. For example, JDK 1.7 will allow you to compile your code using the 1.5 compiler.

请参阅此处的交叉编译部分 http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html 一>

See the "Cross compilation section" here http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

您在Intellij中需要做的是转到文件 - > 项目结构 - > Project 并选择Project SDK为1.7,Project Language Level为7.0

What you need to do in Intellij, is to go to File -> Project Structure -> Project and select the "Project SDK" as 1.7 and the "Project Language Level" as 7.0