Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java IntelliJ 13.1.4 "Lambda expressions are not supported at this language level."

When I try to use the expression value -> value I get an error that says that Lambda is not supported. I am currently using the 1.8 JDK with Lambda support, but I still get the error. My guess is that it is IntelliJ 13.1.4 but I'm not positive.

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()));
  }

}
like image 884
Ibounes Avatar asked Oct 09 '14 17:10

Ibounes


3 Answers

In addition to File > Project Structure > Project > Project Language Level as other has mention,
you should also check File > Project Structure > **Modules** > Sources > Project Language Level and set to 8

like image 64
Shoham Avatar answered Oct 28 '22 22:10

Shoham


Go to

File > Project Structure > Project > Project Language Level

Check if it is 8.0

like image 40
Juan Lopes Avatar answered Oct 28 '22 20:10

Juan Lopes


Aside from the wrong language level this line of code also has compile error (the + operator cannot be applied to 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());

And as for the language level, you can change it a little more easily than going into Project Structure menu. Just position your cursor to the part of the code which shows error, hit ALT + ENTER and select Set language level to 8.0

This is in general a good thing to keep in mind, because in IntelliJ you can easily resolve a lot of warnings and errors from the ALT + ENTER menu.

like image 3
Bohuslav Burghardt Avatar answered Oct 28 '22 22:10

Bohuslav Burghardt