Why is Stream<T> not an Iterable<T> ?
odoepner at gmail.com
Wed Mar 27 08:00:05 PDT 2013
Thanks for you answers so far.
I still wonder what is supposed to happen if stream.iterator() is
called repeatedly on Stream object?
The Javadoc only says "Return an iterator for the elements of this
stream. This is a terminal operation."
If it is a terminal operation, I guess it internally creates a
collection. Would it actually have to recreate that collection every
time someone calls iterator() on it? Or would it just keep a reference
to the collection and effectively return something like
coll.iterator() on subsequent iterator() calls?
If, as several people said here, the semantics are so different from
Iterable, then that should be more clearly documented in the method's
javadoc, I think.
More information about the lambda-dev