[英]Java IntelliJ 13.1.4 “Lambda expressions are not supported at this language level.”
當我嘗試使用表達式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()));
}
}
除了其他提到的File > Project Structure > Project > Project Language Level
之外,
您還應該檢查File > Project Structure > **Modules** > Sources > Project Language Level
並設置為8
去
File > Project Structure > Project > Project Language Level
檢查它是否是8.0
除了錯誤的語言級別,這行代碼也有編譯錯誤( +
運算符不能應用於System.out.println
返回的void
)。
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菜單中解決許多警告和錯誤。
如果使用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>
使用此屬性可以使用gradle完成相同的操作:
compileJava.sourceCompatibility
compileJava.targetCompatibility
並檢查前面提到的。
文件>項目結構>項目>項目語言級別
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.