这个问题在这里已经有答案了:
标记语法错误,lambda表达式的构造放错位置(2个答案)
26天前关门了。
我不明白为什么Java1.8不支持stream()中的lambda表达式
例如:
来自eclipse ide的错误代码段
import java.util.*;
class GFG {
// Driver code
public static void main(String[] args) {
// Creating a list of Integers
List<Integer> list = Arrays.asList(3, 4, 6, 12, 20);
// Check if all elements of stream
// are divisible by 3 or not using
// Stream allMatch(Predicate predicate)
boolean answer = list.stream().allMatch(n-> n % 3 ==0);
// Displaying the result
System.out.println(answer);
}
}
我在eclipse中得到的错误是“syntax error on token”--“,--expected”和“n”下面的红线。请帮助我理解并解决这个问题。
1条答案
按热度按时间qybjjes11#
你的代码似乎在编译和运行https://www.tutorialspoint.com/compile_java_online.php 它运行java 1.8.0141。检查eclipse中的目标运行时是否设置为java8。
您可以使用eclipse中的目标jre作为示例。