Stream difference between Java 8 and 11
Stream.flatMap( )
causes breaking of short-circuiting of terminal operations -
it was a bug that was fixed starting from Java 10.
It is not a bug but an optimization to make flatMap
work in lazy mode.
One of the beautiful feature improvement I can see, as now I can use flatMap
in Lazy way, with almost fully supporting functional composition rather than just a chain of function execution (if not lazy).
Functional composition is what really excite me every day when I start writing NEW Java code.
Maybe I'm late to the party..!! :P
laziness has changed in case of flatMap
, until java-10, flatMap
was never lazy. see JDK-8075939