我的同事和我有一个错误是由于我们假设空流调用allMatch()将返回false.
if (myItems.allMatch(i -> i.isValid()) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
当然,假设而不是阅读文档是我们的错.但我不明白为什么allMatch()空流的默认行为返回true.这是什么原因?就像anyMatch()(相反地返回false)一样,这个操作以一种离开monad并且可能在if声明中使用的命令性方式使用.考虑到这些事实,是否有任何理由为什么在大多数用途中需要allMatch()默认为true空流?