Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable lambda expression in Java 8 in Intelij [duplicate]

I am trying to follow the spark java tutorial. I set up all things, and tried compiling the project. I got the following error:

Error:(8, 34) java: lambda expressions are not supported in -source 1.5
  (use -source 8 or higher to enable lambda expressions)

I then tried setting the compiler options and the default JDK, but I am still seeing that error.

Here is how I set my IDE:

enter image description here

I would be happy if you could help me.

like image 860
oz123 Avatar asked Sep 30 '15 08:09

oz123


People also ask

Is lambda expressions introduced in Java 8?

Lambda Expressions were added in Java 8. A lambda expression is a short block of code which takes in parameters and returns a value. Lambda expressions are similar to methods, but they do not need a name and they can be implemented right in the body of a method.

Which of the following is are not valid lambda expressions?

Based on the syntax rules just shown, which of the following are not valid lambda expressions? Answer: Only 4 and 5 are invalid lambdas.


2 Answers

It's not enough to set the project level. You need to set up the Module level.

Follow these steps.

Right Click on the project------>> go to Open module Settings--->
In that opening window click the Project in project settings---->
and set project SDK

See this answer https://stackoverflow.com/a/21747364/492620

like image 121
oz123 Avatar answered Sep 24 '22 23:09

oz123


Select project and press alt+ctrl+shift+s and you get Project Structure window where you need to set project sdk and language level for project. enter image description here

Then you should be able to use lambdas.

like image 31
akhil_mittal Avatar answered Sep 24 '22 23:09

akhil_mittal