作者:森南有鹿63N | 来源:互联网 | 2023-02-05 14:23
你不能返回false,因为你在lambda表达式中实现了Consumer函数接口,该方法是void类型.
相反,使用anyMatch或noneMatch或allMatch:
return aMap.entrySet().stream().anyMatch(entry -> {
return false;// Put your condition here
});
我还建议在方法中提取验证,以便您的管道如下所示:
return aMap.entrySet()
.stream()
.anyMatch(this::checkIfMatch);
大多数情况下,打开时{}
,您应该创建一个新方法.
1> Jean-Françoi..:
你不能返回false,因为你在lambda表达式中实现了Consumer函数接口,该方法是void类型.
相反,使用anyMatch或noneMatch或allMatch:
return aMap.entrySet().stream().anyMatch(entry -> {
return false;// Put your condition here
});
我还建议在方法中提取验证,以便您的管道如下所示:
return aMap.entrySet()
.stream()
.anyMatch(this::checkIfMatch);
大多数情况下,打开时{}
,您应该创建一个新方法.
好吧,在这种情况下,您可以将表达式重写为没有大括号的表单,即`x - > condition1 && condition2 && condition3 ...`,但它仍然很大,建议使用专用方法,特别是因为它会有更多通用,比较`AValue`和`BValue`对象,这些对象在其他地方也可能有用.