Java IntelliJ 13.1.4 "Lambda expressions are not supported at this level of the language."
When I try to use the expression value -> value , I get an error message that says Lambda is not supported. I am currently using the 1.8 JDK with Lambda support, but I am still getting the error. I assume this is IntelliJ 13.1.4, but I'm not sure.
public static void grades(){ final List<Integer> grade = new ArrayList<Integer>(); int gradelistnumber = 1; int inputedgrade = 0; while(inputedgrade != -1){ System.out.println("Enter Grade for student " + gradelistnumber + " (1-50): "); inputedgrade = sc.nextInt(); grade.add(inputedgrade); gradelistnumber++; } System.out.println("Class Average: " + System.out.println(grade.stream().mapToInt(value -> value /*error*/).sum())); } } Besides the wrong language level, this line of code also has a compilation error (the + operator cannot be applied to the void returned by System.out.println ).
System.out.println("Class Average: " + System.out.println(grade.stream().mapToInt(value -> value /*error*/).sum())); Change it to:
System.out.println("Class Average: " + grade.stream().mapToInt(value -> value).sum()); As for the language level, you can change it a bit than go to the "Project Structure" menu. Just place the cursor on the part of the code that shows the error, press ALT + ENTER and select Set language level to 8.0
In general, itβs good to remember, because in IntelliJ you can easily resolve many warnings and errors from the ALT + ENTER menu.
Fix maven compiler plugin if you create your project using pom.xml
</dependencies> <build> <finalName>SnmpAgentExample</finalName> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project> The same thing can be done with gradle using properties :
compileJava.sourceCompatibility compileJava.targetCompatibility And also check as mentioned earlier.
File> Project Structure> Project> Project Language Level