更新时间:2021-07-30 14:55:58
人们已经问过同样的问题 在邮件列表中 ☺.主要原因是Iterable也有可重迭代的语义,而Stream没有.
People have already asked the same on the mailing list ☺. The main reason is Iterable also has a re-iterable semantic, while Stream is not.
我认为主要原因是 Iterable
意味着可重用性,而 Stream
是只能使用一次的东西——更像是一个 Iterator
.
I think the main reason is that
Iterable
implies reusability, whereasStream
is something that can only be used once — more like anIterator
.
如果 Stream
扩展了 Iterable
则现有代码在收到抛出 Exception
的 Iterable
时可能会感到惊讶这他们第二次 for (element : iterable)
.
If Stream
extended Iterable
then existing code might be surprised when it receives an Iterable
that throws an Exception
the
second time they do for (element : iterable)
.