On Sat, 6 Nov 2021 17:23:34 GMT, Pavel Rappo <pra...@openjdk.org> wrote:

> Streams are closeable, and a terminal operation may be invoked on a given 
> stream only once. Thus, shouldn't the third line in both of the examples 
> below throw `IllegalStateException`?
> 
> ```
>     Stream<Object> empty = Stream.empty();
>     System.out.println(empty.count());
>     System.out.println(empty.count());
> 
>     Stream<Object> empty = Stream.empty();
>     empty.close();
>     System.out.println(empty.count());
> ```

That would be fairly easy to solve by having two instances of the EmptyStream. 
The terminal operations would return the terminal operation that throws 
IllegalStateExceptions.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6275

Reply via email to