我使用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
我将Compiler合规性级别设置为1.7。怎么了?是问题吗?
最佳答案
您不是在Java 7中编译,而是在Java 6中编译。
项目合规性设置为7,否则try-with-resources将在eclipse编辑器中显示错误。
您应该检查如何构建项目(看起来像ant),并将其配置为在7中编译(使用“-source”参数)。
关于eclipse - 错误: try-with-resources is not supported in -source 1.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12627004/