Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Pattern matching features arrived over several releases (instanceof patterns, switch patterns, record patterns, unnamed patterns, primitive patterns still in preview in Java 25). How would you pace adoption across many teams on different JDK versions?

Adoption is limited by the lowest --release target of each module, and shared libraries usually lag behind services, so I would pace it per LTS: instanceof patterns once a module targets Java 17, switch and record patterns once it targets 21, unnamed variables and patterns once it targets 25, the next LTS after their Java 22 release. Preview features such as primitive patterns, still in preview in Java 25, stay out of production and shared code. Each LTS upgrade comes with style guide, IDE inspection and review training updates, and mechanical cases such as instanceof followed by a cast are migrated automatically.

Why this question is asked

Pattern matching is not one feature but a series that arrived over about six releases, and an organization with many teams will have modules on Java 17, 21 and 25 at the same time. Without a plan, one team adopts a feature that another team's build cannot compile, or a library starts using a preview feature and forces every consumer onto one exact JDK. Interviewers ask this leadership question to see whether we can turn a language roadmap into a predictable adoption plan. In this answer, we will lay out which feature became final when, see why the --release target is the real constraint, look at the rule for preview features, and plan the training and automation that make adoption happen.

1The Timeline of Pattern Matching

Each feature went through one or more preview rounds before becoming final, and only final features belong in production code. Lining them up against the long-term support releases, the ones most organizations run in production, gives the natural pacing.

Pattern matching features and the LTS that brings them
FeatureFinal inFirst LTS
Pattern matching for instanceof (JEP 394)Java 16Java 17
Sealed classes (JEP 409)Java 17Java 17
Pattern matching for switch (JEP 441)Java 21Java 21
Record patterns (JEP 440)Java 21Java 21
Unnamed variables and patterns (JEP 456)Java 22Java 25
Primitive types in patternsstill preview in Java 25not yet
Adopt by LTS, not by release: each row becomes available when a module targets that LTS.

2The Real Constraint: --release of Each Module

A language feature is available to a module only if that module is compiled with a high enough language level, which in Maven or Gradle usually means the --release option, for example maven.compiler.release set to 21. The JDK a service runs on does not matter; a service running on Java 25 but compiled with --release 17 cannot use switch patterns.

Shared libraries usually have the lowest target in the organization, because they must run in every consumer. If a library is consumed by services on Java 17 and 21, it must be compiled for 17, so it cannot use switch patterns even though most of its consumers could. So adoption is decided module by module: each module may use every final feature its own --release allows, and the plan moves library targets forward only after the oldest important consumer has upgraded.

XML
<!-- payments-service: may use switch and record patterns -->
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
<!-- shared-payments-model: still consumed by Java 17 services -->
<properties>
<maven.compiler.release>17</maven.compiler.release> <!-- instanceof patterns only -->
</properties>

3Keep Preview Features Out

A preview feature is complete enough to try but may still change or be removed. To use one, we must compile and run with --enable-preview, and the resulting class files are marked so that they run only on that exact JDK feature version: a class compiled with preview features on Java 25 refuses to load on Java 26. For a service, that ties every deployment to one JDK version and to a feature that may change shape in the next release. For a shared library, it is worse, because every consumer inherits the flag and the exact JDK requirement.

So the rule is simple: no preview features in production code or shared libraries. Experiments in a sandbox repository or in tests of a spike branch are welcome, because that is how teams learn what is coming, and primitive patterns, in preview again in Java 25, are a good subject for such experiments.

4Updating Guidance With Each LTS

New syntax spreads through examples and reviews, not through announcements. With each LTS upgrade, I would update three things together. The style guide gains short examples of the newly available features and when to prefer them, such as a switch over a sealed type instead of an if-else chain with casts. The IDE inspections, shared through a checked-in configuration, are turned on for the new features, so IntelliJ or Eclipse suggest the pattern form where it applies. And code review training, a short session and a few annotated pull requests, helps reviewers recognise good and bad uses, for example a switch with a default that hides missing sealed cases.

Step throughAdoption step for each LTS upgrade
  1. Module moves to new --releaseafter its oldest consumer can follow
  2. Style guide and examples updatedwhat to prefer, what to avoid
  3. IDE inspections enabledshared configuration in the repository
  4. Automated migration of mechanical casese.g. instanceof followed by a cast
  5. Review trainingshort session, annotated pull requests

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

The same five steps repeat at 17, 21 and 25.

5Automating the Mechanical Cases

Some rewrites are purely mechanical and safe: an instanceof check followed by a cast of the same variable becomes a type pattern, with identical behaviour. These should not consume review time. Refactoring tools such as OpenRewrite have recipes for upgrades to a given Java version that include this kind of change, and IntelliJ can apply its inspection fixes across a project. Check the recipe catalog for your OpenRewrite version for the exact recipe names.

Java
// before, found by the tool
if (event instanceof OrderPlaced) {
OrderPlaced placed = (OrderPlaced) event;
publish(placed.orderId());
}
// after, applied automatically
if (event instanceof OrderPlaced placed) {
publish(placed.orderId());
}

Changes that alter structure, such as turning an if-else chain into a switch over a sealed type, are not mechanical, because they change exhaustiveness and default behaviour. Those happen by hand, when a team is working in the code anyway. Running the automated recipes as a single, separate commit per repository keeps the history readable and the review trivial.

6Follow-up questions

What if one team wants to move a shared library to Java 21 early?

Then the library's consumers on Java 17 cannot upgrade it. The options are to wait, to keep a Java 17 maintenance branch, or to publish a multi-release JAR, which is complex and rarely worth it for syntax. Usually the right answer is to wait until the oldest important consumer has moved.

Does using new syntax affect runtime performance?

Not in any way that should drive adoption. instanceof patterns compile to the same checks and casts. Pattern switches use an invokedynamic-based type switch that performs well. The reasons to adopt are correctness and readability.

How do we know adoption is happening?

Count the remaining instances of the old forms with the same tools that find them, such as IDE inspection reports or OpenRewrite dry runs, per repository and over time. A falling count after each LTS upgrade shows the plan is working without anyone counting new lines of fancy syntax.

7Conclusion

In this answer, we paced pattern matching adoption by LTS: instanceof patterns with Java 17, switch and record patterns with Java 21, unnamed variables and patterns with Java 25, because the real constraint is each module's --release target and shared libraries lag behind services. Preview features, such as primitive patterns in Java 25, stay out of production and shared code because they tie class files to one JDK. Each LTS upgrade brings style guide, IDE inspection and review training updates, and mechanical rewrites are automated.

What to say in the interviewAbout 100 seconds aloud

Open with

I would pace it by LTS and by module rather than by announcement. The real constraint is each module's --release target, not the JDK the service runs on, and shared libraries usually have the lowest target because they must work in every consumer.

Then, if they want more

So the rule is: a module may use every final feature its own release level allows. Instanceof patterns, final in Java 16, are available from Java 17. Switch patterns and record patterns, final in Java 21, from 21. Unnamed variables and patterns, final in Java 22, from the next LTS, Java 25.

Libraries move their target forward only after their oldest important consumer has. Preview features stay out of production and out of shared code completely. They need --enable-preview at compile and run time, and the class files only load on that exact JDK version, so a library using them would force every consumer onto one JDK.

Primitive patterns are still in preview in Java 25, so they are for experiments only. With each LTS upgrade, I would update the style guide with examples, turn on the matching IDE inspections in a shared configuration, and run a short review training.

Mechanical changes, like instanceof followed by a cast becoming a type pattern, I would apply automatically with OpenRewrite or IDE batch fixes, in a separate commit per repository. Structural changes, like moving an if-else chain to an exhaustive switch over a sealed type, happen by hand when a team works in that code.

About this answer

Last updated
12 November 2026
Versions it names
Java 17, Java 25, Java 21, 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 "Pattern matching features arrived over several releases (instanceof patterns, switch...": https://scrivio-interview-library.netlify.app/java/sealed-and-pattern-matching/0f11e953e4/