RFR: 8357647 : Stream gatherers forward upstream size information to downstream

Viktor Klang vklang at openjdk.org
Fri May 23 16:08:52 UTC 2025


On Fri, 23 May 2025 16:04:50 GMT, Viktor Klang <vklang at openjdk.org> wrote:

>> src/java.base/share/classes/java/util/stream/GathererOp.java line 153:
>> 
>>> 151:             if (initializer != Gatherer.defaultInitializer()) // Optimization
>>> 152:                 state = initializer.get();
>>> 153:             sink.begin(-1); // GathererOp does not know the size of the output
>> 
>> The Integrator of the SO question which motivated this PR _does_ know the size of the output. In general would it be worth to enhance Integrator with something like `default long estimateSize(long streamEstimate) { return -1; }` to allow Integrator implementations to weigh in?
>
> @jdlib I guess that would depend on the definition of *value* and *cost* in this context.

API modifications would definitely be its own thing.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25418#discussion_r2104914259


More information about the core-libs-dev mailing list