我有一个班级
public class RegulatoryApproval {
private String approvalType;
private Boolean deleted;
private RegulatorCategory regulatorCategory;
//getters and setters
}
另一个班级
public class RegulatorCategory {
...
private List<CreditReportingField> creditReportingFields;
//getters and setters
}
我收到了RegulatoryApproval列表。我想在一个列表中收集RegulatorCategory中的所有CreditReportingFields。我正在尝试,但我仍然坚持如何做到这一点。
我收到错误
Type mismatch: cannot convert from List<Stream<CreditReportingField>> to List<CreditReportingField>
这就是我在做什么
List<CreditReportingField> creditReportingFields = null;
List<RegulatoryApproval> regulatoryApprovals = regulatoryApprovalRepository.findDistinctByIdInAndDeletedFalse(courseApprovalIds);
if (!CollectionUtils.isEmpty(regulatoryApprovals)) {
creditReportingFields = regulatoryApprovals
.stream()
.map(RegulatoryApproval::getRegulatorCategory)
.filter(p -> p!= null)
.map(RegulatorCategory::getCreditReportingFields)
.filter(p -> !CollectionUtils.isEmpty(p))
.map(p -> p.
stream()
.filter(creditReportingField -> creditReportingField != null)
//.collect(Collectors.toList())
)
.collect(Collectors.toList());
}
我该如何收集它?这种方法是正确的还是有更好的方法来做到这一点?
由于