【问题标题】:check if all Objects of a stream meet a rule [duplicate]检查流的所有对象是否符合规则[重复]
【发布时间】:2019-10-16 08:25:01
【问题描述】:

我想检查一个流的所有对象是否都符合规则,只有当所有对象都符合规则时才返回True, 但我有一个编译错误:Role cannot be applied to lambda parameter

public static Predicate<Hostel> areAllTrue() {
   return req -> req.getRole().stream(r -> isTrue(r));
}


private static boolean isTrue(HostelRole hostelRole) {

}

【问题讨论】:

标签: java lambda java-8 functional-programming java-stream


【解决方案1】:

使用终端操作allMatch

public static Predicate<Hostel> areAllTrue() {
   return req -> req.getRole().stream().allMatch(r -> isTrue(r));
}

【讨论】:

    猜你喜欢
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2013-12-26
    • 1970-01-01
    • 2016-09-04
    • 2014-05-08
    • 1970-01-01
    相关资源
    最近更新 更多