【问题标题】:error: try-with-resources is not supported in -source 1.6错误:-source 1.6 不支持 try-with-resources
【发布时间】:2012-09-27 17:33:22
【问题描述】:

我使用 Linux Debian 2.6.32-5-amd64。 我的 Eclipse 版本:4.2.0 我的Java版本:jdk1.7.0_07

当我构建项目时出现错误:

[javac] <myPath>file.java:66: error: try-with-resources is not supported in -source 1.6
[javac]         try(Scanner scanner = new Scanner(new File(path))){
[javac]            ^
[javac]   (use -source 7 or higher to enable try-with-resources)
[javac] 1 error

我将编译器合规级别设置为 1.7。怎么了?有问题吗?

【问题讨论】:

  • 你能显示你的命令行吗?因为您的合规级别似乎未设置为 7。

标签: eclipse build syntax-error java-7 try-with-resources


【解决方案1】:

您不是在 java 7 中编译,而是在 java 6 中编译。 项目合规性设置为 7,否则 try-with-resources 会在 eclipse 编辑器中显示错误。

您应该检查您是如何构建项目的(看起来像 ant)并将其配置为在 7 中编译(使用“-source”参数)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-15
    • 2013-06-10
    • 2014-08-09
    • 2014-06-29
    • 2018-10-20
    • 1970-01-01
    • 2014-01-06
    相关资源
    最近更新 更多