Vscode-java: '<>' operator is not allowed for source level below 1.7

Created on 3 Jun 2018  Â·  6Comments  Â·  Source: redhat-developer/vscode-java

I'm getting the error: '<>' operator is not allowed for source level below 1.7 in VSCode on a code line like this:
List<Integer> v0 = new ArrayList<>();
The interesting part is that I do not have any JDK installed lower than 1.8.
I am wondering how I could configure the compiler with which option to recognize source as 1.8 and target as 1.8.

Environment
  • Operating System: MacOS High Sierra 10.13.4
  • JDK version: 1.8.0_172
  • Visual Studio Code version: 1.23.1
  • Java extension version: 0.3.0
Steps To Reproduce

Java environment is identified though JAVA_HOME environment variable pointing to: /Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home/
Any <> operator causes this error in compilation in my setup.

Maven not-a-bug

Most helpful comment

In case anybody runs into this issue like I did today, I fixed this by adding a <properties> tag to my pom.xml:

<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>

Source: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

Thanks everyone in this thread, it was very helpful!

All 6 comments

Do you see that in a Maven, Gradle or Eclipse project? or a standalone file?
Please note for Maven projects, you need to set the compiler configuration source and target to 1.8, as the default is set to 1.5.

Was facing the same issue. The linter will whine for using any language feature above version 1.5(lambdas, try-with-resources).
Changing the Maven source, target works. Thanks @fbricon

Okay. That’s the issue then.
I’ll fix my maven file and then it should work.
Sorry for that.
Best
Roman

On 6 Jul 2018, at 05:14, Siddharth Shishulkar notifications@github.com wrote:

Was facing the same issue. The linter will whine for using any language feature above version 1.5.
Changing the Maven source, target works. Thanks @fbricon

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

The suggested solution was to correct the Maven project settings, but the problem occurs even when there is no problem there (the project builds from the command-line).

It seems like this may be an issue in 'Microsoft/vscode-maven'

In case anybody runs into this issue like I did today, I fixed this by adding a <properties> tag to my pom.xml:

<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>

Source: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

Thanks everyone in this thread, it was very helpful!

In case anybody runs into this issue like I did today, I fixed this by adding a <properties> tag to my pom.xml:

<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>

Source: https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

Thanks everyone in this thread, it was very helpful!

Thank you. This resolves my problem!

Was this page helpful?
0 / 5 - 0 ratings