当我尝试使用表达式value -> value
时,我收到一条错误消息,指出不支持Lambda。我目前正在使用1.8 JDK和Lambda支持,但我仍然得到错误。我的猜测是它是IntelliJ 13.1.4,但我并不积极。
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()));
}
}
答案 0 :(得分:16)
另外至File > Project Structure > Project > Project Language Level
正如其他人所提及的那样,
您还应该检查File > Project Structure > **Modules** > Sources > Project Language Level
并设置为8
答案 1 :(得分:8)
转到
File > Project Structure > Project > Project Language Level
检查是否为8.0
答案 2 :(得分:3)
除了错误的语言级别,这行代码也有编译错误(+
运算符无法应用于void
返回的System.out.println
。
System.out.println("Class Average: " + System.out.println(grade.stream().mapToInt(value -> value /*error*/).sum()));
将其更改为:
System.out.println("Class Average: " + grade.stream().mapToInt(value -> value).sum());
至于语言级别,您可以比进入项目结构菜单更容易地更改它。只需将光标定位到显示错误的代码部分,点击 ALT + ENTER 并选择将语言级别设置为8.0
这通常是一件好事,请记住,因为在IntelliJ中,您可以轻松地从 ALT + ENTER 菜单中解决许多警告和错误。< / p>
答案 3 :(得分:3)
如果使用pom.xml
构建项目,请修复maven编译器插件 </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>
使用此properties:
可以使用gradle完成相同的操作compileJava.sourceCompatibility
compileJava.targetCompatibility
并且如前所述进行检查。
档案&gt;项目结构&gt;项目&gt;项目语言水平