Empty should be empty!

The shock and surprise when I saw the memory cost of a Stream created from an empty List in #Java was audible.
https://donraab.medium.com/empty-should-be-empty-c09e21edc205?source=friends_link&sk=c7809f108441527f48b2ef173bc7fbda

Empty Should be Empty

Why does empty cost so much in Java sometimes?

Medium
@TheDonRaab hi! You cannot return a singleton stream from an empty list, as any stream has a state. It tracks whether it's consumed, so you get IllegalStateException when trying to consume it twice. Also, you can register close handlers via onClose(). I believe, LazyIterable doesn't have such a (arguably not very useful but still) feature.
@tagir_valeev Hi, I was about to go to sleep after publishing and then went and updated my blog because I remembered that Streams can't be used more than once as you rightly point out here. Then I saw your post with a bunch of great points. Thanks for the replies and advice!
@TheDonRaab the stream would be much simpler without parallelism support. It would be possible to have separate sequential stream and parallel stream implementations. As parallel is used rarely, many people would benefit in terms of CPU+allocations when using sequential only. However, .parallel() returns the same instance with a flag set, and I believe existing code already relies on this unspecified behavior...