我想的foreach转换成流JAVA的foreach到流
for (Entity entity : listOfEntitys.getAll()) {
if (!isEntityDateValid(entity.getStartDate())
|| !isEntityDateValid(entity.getEndDate())) {
return false;
}
}
所以我将它转换这样
if (listOfEntitys.getAll() != null) {
return listOfEntitys.getAll().stream().anyMatch(entity-> !isEntityDateValid(entity.getStartDate())
|| !isEntityDateValid(entity.getEndDate()));
}
但我搞砸了,因为它的结果总是布尔值和我只在满足条件时才返回它
条件返回语句不能更改为纯流,但如果您向我们展示更多代码,我们可能会帮助您 – ByeBye
无需空检查,因为如果getAll返回null,for-each也会失败。 – john16384