<分区>
下面是我的普通 for 循环,我想重构相同的代码以使用 java8 IntStream。
for(int i=0; i<= historyList.size(); i++) {
if (isExist(historyList, status, i)) {
return historyList.get(i).getCreated();
}
}
下面是重构后的IntStream
版本
IntStream.rangeClosed(0, historyList.size()).forEach(i -> {
if (isExist(historyList, status, i)) {
return historyList.get(i).getCreated(); -- Error: Unexpected return value
}
});
但如上所示在返回时出现错误。
Error: Unexpected return value
如何以适当的方式重构上述代码?