Try With Resources Not Supported at This Language Level

十年热恋 提交于 2019-12-21 11:36:24

问题


I'm using IntelliJ IDEA Ultimate 2016.2.1, have set Project SDK to my 1.8 version, Project Language Level to 8, Module SDK to my 1.8 version, and JDK home path to /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home.

I have restarted the IDE.

Still, I am getting ugly warnings about try-with-resources not supported at this language level. I have not used less than language level 8 in IntelliJ so this can't be due to something not refreshing. I am using a gradle build configuration - cleaned built and tried to run - says I'm running 1.5 but I can't figure out where 1.5 is mentioned. In build.gradle i'm using:

 apply plugin: 'java'
 apply plugin: 'application'
 sourceCompatibility = 1.8

Should I file an IntelliJ bug or am I still missing something?

EDIT:

Running gradle in termianl outside of IntelliJ's system runs it fine. So the problem is IntelliJ related.


回答1:


I have found that IntelliJ sometimes defaults modules to language levels that don't match the set project SDK. Try right clicking on the module in the project explorer and select module settings and then the language level tab. If that is set to Java 5 then update it to Java 8.




回答2:


Hey @Calicoder just try to make change your Java compiler version into 1.7 or 1.8 as mentioned below

Thanks hope this will help.




回答3:


Make sure your try-with-resources is using the correct semantics. For instance, this:

try (new BufferedReader(request.getReader())) {

}

will produce that same error message.



来源:https://stackoverflow.com/questions/38965221/try-with-resources-not-supported-at-this-language-level

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!