Quick revision
The short answer
I would find every class that implements List or Deque, or extends LinkedHashMap, LinkedHashSet or another collection class, and declares a method named like the new ones, such as getFirst, reversed or removeLast. Methods with matching names but different return types will fail to compile, classes implementing both List and Deque must override reversed(), and libraries compiled on 17 keep running on 21 but may fail when recompiled. So I would run every build on 21 early, in parallel with the 17 builds, and fix the conflicts before the fleet upgrade.
What to remember
In this answer, we assessed the impact of sequenced collections by building an inventory of classes that extend or implement the affected types and declare the new method names, confirmed by a non-blocking JDK 21 build. We sorted findings into incompatible return types, List and Deque classes that must override reversed(), and silent overrides that need review. Libraries compiled on 17 keep running on 21, but must be rebuilt and fixed by their owners first, and the rollout goes libraries first, then services, with --release 17 as a stepping stone.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would find every class that implements List or Deque, or extends LinkedHashMap, LinkedHashSet or another collection class, and declares a method named like the new ones, such as getFirst, reversed or removeLast. Methods with matching names but different return types will fail to compile, classes implementing both List and Deque must override reversed(), and libraries compiled on 17 keep running on 21 but may fail when recompiled. So I would run every build on 21 early, in parallel with the 17 builds, and fix the conflicts before the fleet upgrade.
Why this question is asked
A platform upgrade across many teams is a coordination problem as much as a technical one. Most of a Java 17 to 21 move is uneventful, but sequenced collections are one of the few changes that can break source code, and they hit internal utilities and shared libraries that dozens of services depend on. An interviewer asking this wants to see a systematic way to measure the impact, separate real risk from noise, and sequence the work so no team is blocked on upgrade day. In this answer, we will recap exactly what changed, build an inventory, sort what we find into kinds of breakage, handle libraries, and plan the rollout.
1A Quick Recap of What Changed
JEP 431 added three interfaces in Java 21. SequencedCollection became a parent of List and Deque and brought getFirst, getLast, addFirst, addLast, removeFirst, removeLast and reversed. SequencedSet sits above LinkedHashSet and SortedSet, and SequencedMap above LinkedHashMap and SortedMap, adding firstEntry, lastEntry, pollFirstEntry, pollLastEntry, putFirst, putLast, reversed and the sequencedKeySet, sequencedValues and sequencedEntrySet views. The concrete classes, such as ArrayList and LinkedHashMap, got their own implementations of many of these.
These are default or inherited methods, so most code is untouched. The risk is limited to classes that already declare methods with these names, and classes that implement two of the affected interfaces at once. That makes the impact measurable: we are searching for a known list of names in a known set of types.
2Build an Inventory
A quick text search gives a first estimate across all repositories. It looks for classes that implement or extend the affected types, and then for those that declare one of the new method names.
The search is deliberately broad and will over-report, which is fine for an estimate. It also misses classes that reach List through an intermediate interface of our own. So it is only the first pass. The authoritative check is the compiler: we add a CI job that builds every service and library with JDK 21, and the job's error list is the real inventory. Running it in parallel with the normal 17 build, and not blocking merges at first, costs teams nothing.
3Sort What We Find
Every finding falls into one of three kinds, and each needs a different response.
- Candidate class foundImplements or extends an affected type and declares a new method name
- Does it fail to compile on 21?Check the JDK 21 CI jobYesRename the method, or override reversed()NoCheck the method's meaning
- Same meaning as the new contract?For example,
getFirstthrows on emptyYesKeep it; add a testNoRename it, so the standard method is used
3 steps in order. Play them, or step through them one at a time.
The silent overrides need a human decision; the compile errors announce themselves.
The first kind is a hard compile error from an incompatible return type, such as an Optional<E> getFirst() on a class extending ArrayList. These are easy to find, because the build fails, and easy to fix by renaming the method and updating callers.
The second kind is a compile error in a class that implements both List and Deque, because it inherits two reversed() defaults; the fix is to override reversed() with a return type that is both, as the JDK's LinkedList does.
The third kind is the dangerous one: a method with a matching signature, such as an old E getFirst() that returns null when empty. It compiles silently and now overrides the standard default, so every caller using the List interface gets its behaviour. These only show up in the inventory search, not in the build, so each one needs a person to read it and decide whether its semantics match the new contract.
4Handle Libraries Separately
Libraries need their own treatment, because there are two different questions. Will a library compiled on 17 run on 21? Almost always yes. Java's binary compatibility rules allow new default methods, and the JVM links methods by name and erased descriptor, so old class files keep working. We confirm this by running each service's tests on a 21 runtime with its existing jars.
Will the library still compile when its owners rebuild it on 21? That is where the source incompatibilities appear. For internal libraries, the owning team runs the 21 build first and publishes a release that compiles on both, ideally one that still targets 17 with --release 17 so that services can adopt it before they upgrade. For third-party libraries, we check that the versions we use are already tested on 21 and plan upgrades for those that are not. A silent override inside a library is worth a quick look too, because it changes behaviour for every service that uses the library's collections through standard interfaces.
5Sequence the Rollout
The order that keeps teams unblocked is libraries first, then services. Shared libraries are fixed and released in versions that work on both 17 and 21. Services then switch their CI to the 21 JDK while still compiling with --release 17, which uses the Java 17 API and so hides the new methods; this step changes the runtime and the tools but not the source. Finally, each service moves to --release 21, at which point the compiler sees the new methods and any remaining conflicts surface in that team's own build.
Throughout, I would keep one shared tracking page with the inventory, the owner of each finding and its status, and set a date after which the 21 build becomes blocking. The whole sequenced-collections part of the upgrade is usually small, a few dozen classes in a large company, but doing it early prevents it from becoming the surprise that delays the fleet upgrade by weeks.
6Follow-up questions
Why compile with --release 17 on a JDK 21 first?
The --release flag makes javac compile against the exact API of the named Java version, so the new sequenced methods are invisible and nothing breaks. It lets a team move its build and runtime to 21 in one step and its source level in a second step, so each change is small and easy to roll back.
Can a static analysis tool find the silent overrides?
Yes. An ArchUnit rule, or a small scan with a bytecode library, can list every class assignable to List, Deque, SequencedSet or SequencedMap that declares a method with one of the new names. Running it on our own classes and our dependency jars gives a complete list, including cases the text search misses.
What about code that calls the old idioms, such as get(0)?
That keeps working unchanged. Moving to getFirst is an optional clean-up that teams can do later, and they should note that getFirst throws NoSuchElementException on an empty list where get(0) threw IndexOutOfBoundsException.
7Conclusion
In this answer, we assessed the impact of sequenced collections by building an inventory of classes that extend or implement the affected types and declare the new method names, confirmed by a non-blocking JDK 21 build. We sorted findings into incompatible return types, List and Deque classes that must override reversed(), and silent overrides that need review. Libraries compiled on 17 keep running on 21, but must be rebuilt and fixed by their owners first, and the rollout goes libraries first, then services, with --release 17 as a stepping stone.
Open with
I would treat it as a measurable, bounded risk. The only code affected is classes that implement List or Deque, or extend collection classes like ArrayList or LinkedHashMap, and also declare methods with the new names, like getFirst, getLast, reversed, removeLast or putFirst, plus classes that implement both List and Deque.
Then, if they want more
So first I build an inventory: a quick search across repositories for those types and names, and, more importantly, a non-blocking CI job that compiles every service and library on JDK 21. Then I sort the findings.
If a method has the same name but an incompatible return type, like getFirst returning Optional, it fails to compile and we rename it. If a class implements both List and Deque, it inherits two reversed defaults and must override reversed with a type that is both, like LinkedList does.
The risky case is a method that matches exactly, for example a getFirst that returns null on empty. It compiles silently and now overrides the standard method, so someone has to review its meaning.
For libraries, code compiled on 17 still runs on 21, but recompiling may fail, so library owners fix and release first, ideally versions that work on both. Then services move their JDK to 21 while keeping --release 17, and later switch to release 21.
I would track every finding with an owner and make the 21 build blocking only once the list is clear.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 17
- 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.
- Official documentation
- The Collections Framework, overview, java.util, package documentation
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 "Your platform is moving from Java 17 to 21. Sequenced collections added new default...": https://scrivio-interview-library.netlify.app/java/collections-overview/67126591ee/