Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

A team asks to enable --enable-preview in production builds to use primitive patterns. What questions do you ask and what is your decision rule?

I would ask what the feature gives us over the code we write today, whether it can wait for the final version, and who will pay for the JDK upgrades it ties us to. Preview class files only run on the exact JDK feature release that compiled them, preview features can change or be withdrawn as string templates were, and every upgrade then forces code changes and coordinated rollouts. My rule is no preview features in production services or shared libraries, while experiments and prototypes may use them freely.

Why this question is asked

Every JDK release ships a few preview features, and engineers who like them naturally want to use them. A tech lead or architect is asked to decide, and the decision has consequences far beyond the line of code that uses the feature. Interviewers ask this to see whether we understand what preview really means technically, and whether we can turn that into a clear, fair rule that does not just say no. In this answer, we will recap what preview means and what --enable-preview does, go through the questions to ask, weigh the value against the cost with a concrete example, and finish with the decision rule and how to keep it from feeling arbitrary.

1A Quick Recap of Preview and --enable-preview

A preview feature is complete and specified, but not yet permanent. The JDK developers ship it to gather feedback, and they reserve the right to change it or remove it. Primitive patterns, which let instanceof and switch work with types such as byte and double, are a preview in Java 25 (JEP 507), their third round.

To use one, we compile with javac --release 25 --enable-preview and run with java --enable-preview. The compiler then marks the class files in a special way, with a minor version number reserved for preview. A JVM refuses to load such a class file unless preview is enabled and the JVM is the very same feature release, Java 25 in this case. Java 26 will not run them, even with the flag.

2The Questions to Ask

First, what value does the feature give us? For primitive patterns, the honest answer is usually a nicer way to write range checks before narrowing casts. That is pleasant, but we already have working code for it, such as a bounds check or Math.toIntExact.

Second, can it wait? The feature has been through three previews, which suggests it is close to final, but nobody can promise when. If a final version arrives in a year, we lose only a year of slightly shorter code.

Third, what are the consequences for the build and the platform? Enabling preview in one module means every class file in it is tied to one JDK release. Every service using the module must run exactly that release, and moving to the next JDK means recompiling, perhaps changing code if the feature changed, and releasing everything together. If the module is a shared library, that tie spreads to every team that depends on it.

Fourth, what is the exit plan if the feature is withdrawn? String templates were previewed in Java 21 and 22 and then removed in Java 23. Teams that had used them in production had to rewrite that code before they could upgrade.

Step throughDeciding on a request to use a preview feature
  1. Is it production code or a shared library?
    YesContinue to the cost checkNoAllowed: experiments and prototypes
  2. Does it solve something current code cannot?
    YesWeigh it against upgrade costNoWait for the final version
  3. Can we pin one JDK and rewrite if it changes?
    YesRare exception, written and time-boxedNoWait for the final version

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

Most requests end at the second question.

3Weighing It With a Concrete Example

Suppose a team of six owns a pricing service and wants primitive patterns for about 40 range checks. Writing them with patterns saves perhaps 80 lines and makes them a little clearer. Now look at the cost. The service is pinned to Java 25 until the feature is final. When the platform team rolls out Java 26 for a security or performance reason, this service cannot follow until it is recompiled and retested, and if the feature changed in the next preview, the 40 sites must change too. The service now has a different upgrade path from every other service, which is exactly the kind of exception that becomes a long-lived problem.

Put side by side, the benefit is small and local, and the cost is large and spread over time and other teams. That shape is typical for preview features in production, which is why the rule can be simple.

4The Decision Rule

The rule I would write is: no preview features in production services or in shared libraries. They are welcome in prototypes, spikes, internal tools that are rebuilt often, tests that explore the feature, and side projects. When a feature becomes final, we adopt it in the normal way, and the people who experimented early become the ones who know it best.

There is room for an exception, but it should be rare, written down, and time-boxed: a specific feature that solves a problem current code cannot, a team that accepts pinning to one JDK, and an agreed plan to rewrite if the feature changes. In practice almost no request passes that bar, and having the bar written down makes the conversation about the facts rather than about who is being cautious.

5Keeping the Rule From Feeling Arbitrary

Engineers who ask for preview features are usually the ones who care most about the language, and we do not want to discourage them. So the response should explain the reasoning, point to an experimental module or sandbox repository where they can use the feature, and invite them to share what they learn. It also helps to enforce the rule automatically: a build check that fails if --enable-preview appears in production modules turns the policy into something nobody has to police by hand, and a short note in the engineering guidelines links to the explanation.

6Follow-up questions

Is incubator status the same as preview?

No. Incubator modules, such as the Vector API in jdk.incubator.vector, are APIs in separate modules that are not yet final, enabled with --add-modules. They carry a similar risk of change, and the same rule usually applies, though an incubator API does not mark our class files the way language previews do.

What if the team only uses the preview feature in tests?

Tests are a reasonable place to experiment, but tests are compiled code too. If they need --enable-preview, the test build is tied to one JDK release, so CI upgrades get harder. A separate experimental test module limits the effect.

Does a third preview mean the feature is safe to use?

It suggests the design is close to settled, but it is not a guarantee. A feature can still change between previews, and the class file restriction applies until it is final, so the cost of pinning the JDK remains the same.

7Conclusion

In this answer, we looked at a request to enable preview features in production. We saw that preview class files only run on the exact JDK release that compiled them, that features can change or be withdrawn as string templates were, and that each upgrade then forces code changes and coordinated releases. The questions to ask are about value over current code, whether it can wait, and who pays for upgrades. The rule that follows is no previews in production services or shared libraries, with experiments welcome and rare, written exceptions.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start by asking what the feature gives us over what we have. For primitive patterns, it is mostly nicer range checks before narrowing casts, which we can already write with a bounds check or Math.toIntExact.

Then, if they want more

Then I would ask whether it can wait for the final version, and what it costs us. The cost is the important part. Preview class files are marked specially and only run on the exact JDK feature release that compiled them, so a service built with --enable-preview on Java 25 will not run on Java 26.

That pins the service, and if it is a shared library, every consumer, to one release. Preview features can also change or be withdrawn; string templates were previewed twice and removed in Java 23. So every JDK upgrade would mean recompiling, possibly rewriting, and coordinating releases, while the rest of the platform moves on.

My decision rule is no preview features in production services or shared libraries, but they are welcome in prototypes, spikes and experimental modules. I would explain the reasoning rather than just refuse, give the team a sandbox to try it, and add a build check that fails if --enable-preview appears in production modules.

When the feature becomes final, we adopt it normally, and that team will already know it well.

About this answer

Last updated
12 November 2026
Versions it names
Java 25, Java 26, Java 21, Java 23
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 "A team asks to enable --enable-preview in production builds to use primitive patterns....": https://scrivio-interview-library.netlify.app/java/sealed-and-pattern-matching/596470f4fb/