Vscode-java: [Java] Lambda expressions are allowed only at source level 1.8 or above

Created on 12 Oct 2017  路  9Comments  路  Source: redhat-developer/vscode-java

I try to use lambda's but I get the following error:

[Java] Lambda expressions are allowed only at source level 1.8 or above

In my user settings I have set:

"java.home": "/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home"

How can I set the source level?

Environment
  • Operating System: OSX
  • JDK version: jdk1.8.0_144
  • Visual Studio Code version: 1.17.1
  • Java extension version: 0.1.0
need info

Most helpful comment

Do you use Maven to build your app, or something else?

When using Maven, you need to set the maven-compiler-plugin source and target elements to 1.8

All 9 comments

Do you use Maven to build your app, or something else?

When using Maven, you need to set the maven-compiler-plugin source and target elements to 1.8

These 'errors' are quite common in Java projects in VS.

[Java] Syntax error, annotations are only available if source level is 1.5 or greater
[Java] Method references are allowed only at source level 1.8 or above
[Java] Lambda expressions are allowed only at source level 1.8 or above

They don't affect the files, as they compile fine. I was informed such errors occur when the project hierarchy is not properly setup. Is there a way to silence them? I am writing simple class files using an open folder as a mock 'directory' with javac, java to run them.

Same problem here. I'm using Gradle. Is there any way I can set it up or suppress the error?
Ok. I set gradle to use 1.8 and it works for me now.

Change the extension generated file .settings/org.eclipse.jdt.core.prefs

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

@UtkarshGupta-CS Thank you so much. It has solved my problem.

Close this issue as it had been solved. Project setting issue.

Do you use Maven to build your app, or something else?

When using Maven, you need to set the maven-compiler-plugin source and target elements to 1.8

You're the best.

add maven-compiler-plugin source and target elements to 1.8 to pom file sovle this problem

@ylilarry Can you please elaborate on how you accomplished this?

Was this page helpful?
0 / 5 - 0 ratings