Shortcuts on Collections to create Streams
gzsombor at gmail.com
Thu Mar 4 06:56:31 UTC 2021
Thanks, so I'm late by about 4 months for that method.
I've found the tickets about this for future reference:
and the pull request - https://github.com/openjdk/jdk/pull/1026
Now, I only miss the 3 other what I've mentioned :)
On Wed, Mar 3, 2021 at 10:53 PM Thiago Henrique Hupner <thihup at gmail.com>
> They have added the Stream#toList in JDK 16:
> Em qua., 3 de mar. de 2021 às 18:45, Zs. <gzsombor at gmail.com> escreveu:
>> As Collection already has a default implementation for 'forEach', I'm
>> wondering why there is no similar shortcuts for a couple of repeating
>> patterns around the Collection <--> Stream transitions?
>> For example, if you could write:
>> collection.map(...) instead of collection.stream().map(...);
>> collection.filter(...) instead of collection.stream().filter(...);
>> Or for the other direction:
>> stream.toList() instead of stream.collect(Collectors.toList())
>> stream.toSet() instead of stream.collect(Collectors.toSet())
>> They are heavily used even in OpenJDK's source code:
>> - 380 results, unfortunately with false matches from javax.xml.stream.
>> - 559 results, unfortunately with false matches from comments or
>> streams().mapToInt or not related code
>> - 367 results
>> - 117 results
>> Any particular reason, why adding these - 4 or more - default method to a
>> collection deemed unnecessary or harmful? Unfortunately I haven't been
>> to find the answers for this question using internet searches.
More information about the jdk-dev