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

Tagir F. Valeev tvaleev at openjdk.org
Wed Nov 8 15:41:41 UTC 2023


On Mon, 6 Nov 2023 11:08:08 GMT, Viktor Klang <vklang at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/stream/Gatherer.java line 308:
>> 
>>> 306:      */
>>> 307:     static <T, R> Gatherer<T, Void, R> ofSequential(
>>> 308:             Integrator<Void, T, R> integrator) {
>> 
>> Probably PECS signature `? super T, ? extends R` could be useful here?
>
> I've thought about that, and since we don't use that for the other parameters (like `initializer`) I don't think it helps changing it here. And the reason this has little effect is that the code calling the factory typically controls the components/parameters/return type.

It's still possible to have a situation where PECS signature could be useful, and I don't see any downsides. A user may want to reuse the same static integrator instead of creating several identical lambdas just because the target type is more specific. Sometimes, people complain later, and you'll have to fix this. For example, see that `Stream.generate()` [was fixed separately](https://bugs.openjdk.org/browse/JDK-8132097). So why not doing this from the very beginning?

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

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


More information about the core-libs-dev mailing list