Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Gatherers became final in Java 24. Your fleet is split between Java 21 and 25. How do you guide teams and shared library owners on adopting gatherers?

I would split the guidance by who can use what. Shared libraries that still support Java 21 consumers must not use gatherers in their API or their code, because Java 21 cannot load or compile against them. Applications that run on Java 25 may use the built-in gatherers wherever they make code clearer. Custom gatherers go into one internal, tested library that requires Java 25, with tests for early termination and parallel combining, instead of copies in every team. And we revisit the rule when the fleet's minimum supported version moves to 25.

Why this question is asked

Every new language feature arrives in an organisation that runs several Java versions at once, and the people who own shared libraries feel that tension most. If they adopt a feature too early, they break consumers; too late, and teams copy their own versions of the same helpers. Gatherers are a clean case: final in Java 24, unavailable in 21, and genuinely useful. Interviewers ask this to see how a senior engineer turns a version constraint into clear guidance that teams can follow without a meeting. In this answer, we will recap the technical constraint, write the guidance for each group, explain how to centralise custom gatherers, and plan how the rule changes over time.

1A Quick Recap of the Constraint

Gatherers, the java.util.stream.Gatherer interface and the Gatherers class of built-ins, were a preview in Java 22 and 23 and became a standard API in Java 24. Java 25 is the current long-term support release, and Java 21 is the previous one. So in our fleet, services on 25 have gatherers and services on 21 do not.

The constraint is hard, not stylistic. A library compiled with --release 21, which it must be to run on Java 21, cannot reference Gatherer; the compiler reports that the symbol does not exist. And a library compiled for Java 25 produces class files that a Java 21 JVM refuses to load with an UnsupportedClassVersionError. Multi-release JARs can technically carry a Java 24-plus code path alongside a Java 21 one, but for stream helpers that doubles the code and the testing for very little benefit, so I would not recommend it here.

2Guidance for Shared Library Owners

A shared library's minimum Java version is set by its oldest supported consumer. As long as any consumer runs Java 21, the library stays on --release 21 and does not use gatherers anywhere, not only in its public API. If a library exposes helpers such as batching or distinct-by-key today, they stay as they are, built on collectors, Spliterators or loops.

Owners should, however, prepare. They can mark helpers that a built-in gatherer will replace, such as a batching utility that windowFixed covers, and write in the changelog that these will be deprecated once the library's minimum moves to 25. That way consumers on 25 can start using the built-in in new code, and nobody is surprised by the later removal.

Who may use gatherers, and how
CodeRuns onGuidance
Shared library with Java 21 consumers21 and 25No gatherers; keep existing helpers, plan deprecation
Shared library whose consumers are all on 2525May use built-ins and the internal gatherer library
Application on Java 2525Use built-ins where clearer; custom ones from the internal library
Application on Java 2121No gatherers; upgrade first
Internal gatherer library25 minimumOwned, tested, versioned; the only home for custom gatherers
One rule per kind of code, so nobody has to ask.

3Guidance for Applications on Java 25

Applications that run on 25 have no compatibility problem, so the guidance is about clarity. Built-in gatherers are encouraged where they make code clearer than the alternative: windowFixed for batching database or API calls, windowSliding for neighbour comparisons and moving averages, scan for running totals, and mapConcurrent for bounded concurrent I/O, after the usual review of limits, timeouts and failure handling.

The word clearer matters. A gatherer is not automatically better than a loop. If a team replaces a readable ten-line loop with a pipeline nobody can follow, that is a regression. Code review should ask whether the gatherer makes the intent more obvious, and whether a colleague unfamiliar with gatherers could understand it with a quick look at the Javadoc.

4One Home for Custom Gatherers

Custom gatherers, ones we write ourselves, are where quality can drift. They have edge cases that ordinary code does not: an integrator that ignores the boolean from downstream.push breaks limit and findFirst on large sources; a gatherer that claims parallel support with a wrong combiner gives wrong answers only under parallel load; a finisher may flush its last state twice. If five teams each write their own distinctBy, we get five sets of these bugs.

So the guidance is that custom gatherers live in one internal library, for example stream-gatherers, owned by a named team, requiring Java 25. Each gatherer comes with tests for the empty stream, early termination on an infinite source, nulls, and, if it has a combiner, parallel equivalence with the sequential result. Teams that need a new one contribute it there, with review from the owners, instead of writing it locally. That keeps one tested implementation and one place to fix bugs.

5Revisiting the Rule as the Fleet Moves

The guidance has a built-in expiry. When the platform team sets Java 25 as the minimum supported version, shared libraries can raise their release target, adopt gatherers internally, and deprecate the helpers they marked earlier. That moment should be on the platform roadmap, and the gatherer guidance should be linked from it so it gets updated rather than forgotten.

Meanwhile we can measure readiness: the share of services on 25, and the consumers each shared library still has on 21. A library whose last Java 21 consumer has upgraded can move early, so library owners should check their consumer list each quarter rather than waiting for the whole fleet.

Step throughHow a shared library moves to gatherers
  1. Any consumer still on Java 21?
    YesStay on --release 21, no gatherersNoNext step
  2. Raise the library's release target to 25announce in the changelog first
  3. Replace helpers covered by built-insdeprecate the old ones
  4. Use the internal gatherer library for custom onesno local copies
  5. Remove deprecated helpers in the next major version

5 steps in order. Play them, or step through them one at a time.

The trigger is the library's own consumer list, not a fleet-wide date.

6Follow-up questions

Could a library on Java 21 accept a Gatherer from Java 25 callers?

No, because its own code would have to mention the Gatherer type, which does not exist when compiling for 21. A library can accept generic functional interfaces, such as a Function from Stream to Stream, which a Java 25 caller could implement using gatherers internally, but that is rarely worth the indirection.

Why not let each team write the custom gatherers it needs?

Because custom gatherers have subtle failure modes, ignoring downstream.push results or incorrect combiners, that ordinary tests miss. Centralising them means one implementation gets the careful tests, and every team benefits from fixes. Teams can still contribute; they just do it in one place.

How do you communicate the guidance?

As a short decision record linked from the platform's Java version page, with the table of who may use what, examples of good built-in use, and the path to contribute to the internal library. Library owners get a direct note because they carry the compatibility risk.

7Conclusion

In this answer, we turned the Java 21 and 25 split into guidance for each kind of code. Shared libraries with Java 21 consumers do not use gatherers at all, because they cannot compile or run against them, but they mark helpers that built-ins will replace. Applications on 25 use built-in gatherers where they make code clearer. Custom gatherers live in one owned internal library with tests for early termination and parallel combining. And the rule is revisited as each library's consumers, and eventually the fleet minimum, move to Java 25.

What to say in the interviewAbout 90 seconds aloud

Open with

I would publish guidance by kind of code, because the constraint is hard. Gatherers are final from Java 24, so a shared library that still has Java 21 consumers has to compile with release 21 and cannot reference Gatherer at all, not in its API and not internally; a multi-release JAR could work around it, but for stream helpers it is not worth the duplicated code and tests.

Then, if they want more

So those libraries keep their existing batching or distinct helpers, and mark the ones a built-in like windowFixed will replace, with a deprecation planned for when their minimum moves.

Applications that run on 25 can use the built-in gatherers, windowFixed, windowSliding, scan, fold and mapConcurrent, where they genuinely make the code clearer, and mapConcurrent still gets the normal review of limits and timeouts.

For custom gatherers, I do not want every team writing their own distinctBy, because the bugs are subtle: ignoring the result of downstream.push breaks limit on large streams, and a wrong combiner only fails in parallel.

So they go into one internal library that requires 25, owned by a named team, with tests for empty streams, early termination, nulls and parallel equivalence.

Finally, the rule is revisited: each library checks its consumer list every quarter and moves as soon as its last 21 consumer upgrades, and the platform roadmap links to this guidance for when 25 becomes the fleet minimum.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Java 25, Java 24, Java 22
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Gatherers became final in Java 24. Your fleet is split between Java 21 and 25. How do...": https://scrivio-interview-library.netlify.app/java/streams/0c719f6df3/