RFR: JDK-8319123 : Implementation of JEP-461: Stream Gatherers (Preview)

Viktor Klang vklang at openjdk.org
Wed Nov 8 15:41:40 UTC 2023


On Wed, 8 Nov 2023 14:19:47 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/stream/Gatherer.java line 252:
>> 
>>> 250:      *         Gatherer as input that Gatherer
>>> 251:      */
>>> 252:     default <AA, RR> Gatherer<T, ?, RR> andThen(Gatherer<? super R, AA, ? extends RR> that) {
>> 
>> It would be great to remove AA type parameter, which is mentioned only once, so could be replaced with `?`. This will improve user experience if they happen to need to specify type parameters explicitly.
>
> This is especially important given that often you don't know the AA type at all. E.g., imagine that you are doing `.andThen(Gatherers.fold(...))`, but `fold` returns `Gatherer<T, ?, R>`, so you can specify explicit `RR`, but not `AA`.

Has this proven to be a problem for things like [Collectors.mapping(…)](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/stream/Collectors.html#mapping(java.util.function.Function,java.util.stream.Collector)) ? 🤔 

There's one implication on turning it into a wildcard—it may actually cause issues implementing the composition directly in the override, as you won't have a typename to refer to.

Do you have a concrete example of where the current "encoding" causes a caller-problem?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16420#discussion_r1386796562


More information about the core-libs-dev mailing list