【发布时间】:2020-12-14 18:40:55
【问题描述】:
我不明白为什么 JAVA 1.8 不支持 stream().filter() / allMatch() / anyMatch() 中的 lambda 表达式
例如:
ERROR snippet from 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 中遇到错误,如“令牌“-”、-- 预期的语法错误和“n”下方的红线。 请帮助我理解并解决此问题。
#注意:我使用的是 eclipse 3.8、JAVA 8 (1.8.0_271)
【问题讨论】:
-
Eclipse 3.8 是古老的(8 年和 15 个旧版本)并且不理解 lambda 表达式,请使用现代版本的 Eclipse,例如当前的 2020-09。
-
感谢您的建议。我会用最新的。
标签: java eclipse lambda java-8