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()));
}
}
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
Go to
File > Project Structure > Project > Project Language Level
Check if it is 8.0
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With