Quick revision
The short answer
String templates show that previews are real experiments: Java shipped them twice to gather feedback and then removed them, because once a feature is final it must be supported for decades, so the platform would rather get it right than ship it fast. For a large organization, a sensible policy is to allow preview features in experiments and internal tools but not in production services or shared libraries, to track and give feedback on the JEPs we care about, and to make any team that adopts a preview anyway budget for rewriting that code at each upgrade.
What to remember
In this answer, we saw that string templates were previewed twice and then withdrawn, which shows that Java treats previews as real experiments because final features are supported for decades. Preview code is tied to one JDK release, so in production it turns every upgrade into a rewrite, and in shared libraries it spreads that cost to every consumer. The policy we set allows previews in experiments and internal tools, forbids them in production services and shared libraries with build enforcement and a narrow exception process, keeps us close to the platform through tracking, feedback and early-access builds, and budgets migration cost when a team adopts a preview anyway.
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.
String templates show that previews are real experiments: Java shipped them twice to gather feedback and then removed them, because once a feature is final it must be supported for decades, so the platform would rather get it right than ship it fast. For a large organization, a sensible policy is to allow preview features in experiments and internal tools but not in production services or shared libraries, to track and give feedback on the JEPs we care about, and to make any team that adopts a preview anyway budget for rewriting that code at each upgrade.
Why this question is asked
Senior engineers are expected to decide not only how to use a language, but how much of its newest parts an organization should depend on. Preview features are tempting, because they often solve real problems, and the string templates story is the clearest recent example of what can happen when we lean on them. Interviewers ask this to see whether we understand how Java evolves and can turn that into a policy that protects hundreds of services without stopping teams from learning. In this answer, we will recap how features enter Java, look at what the string templates history teaches, work out the real cost of adopting a preview, and then set out a policy with the reasoning behind each part.
1A Quick Recap of How Features Enter Java
New Java features are proposed as JEPs, JDK Enhancement Proposals, and most large ones pass through a trial stage before they become permanent. A preview feature is a language or JVM feature that is fully specified and implemented, but not yet final. It ships disabled, and we must turn it on with --enable-preview for both compiling and running. An incubator module is the same idea for APIs: a module named jdk.incubator.something that we add with --add-modules, as the Vector API has done for many releases.
The purpose of a preview is feedback. Developers try the feature on real code and report what works and what does not, and the designers can then change it, preview it again or drop it. Most previews end up final after one or two rounds: records were previewed in JDK 14 and 15 and became final in 16, and virtual threads were previewed in 19 and 20 and became final in 21.
- JEP draft and discussionproposal on the OpenJDK mailing lists
- Incubator module or previewoff by default, needs a flag
- Second or later previewchanged after feedback
- Final featureon by default, supported for decades
- Or: withdrawnas string templates were in JDK 23
5 layers, from the top down. Step through them one at a time.
Every stage before final can change or end. Only the final stage carries the compatibility promise.
2What the String Templates Story Teaches
String templates were previewed in JDK 21 and JDK 22, and in the JDK 23 cycle the team concluded that the design, mainly the template processor model, needed rethinking. They withdrew it completely rather than ship something they were unsure of. Nobody who followed the rules was harmed: preview code only ever ran with a flag, on one release.
The lesson is about priorities. Java keeps an unusually strong promise of backward compatibility: code written for Java 8 usually compiles and runs on Java 25. Every final feature therefore becomes something the platform must support for decades and that every later feature must fit around. So the designers are willing to be slow and even to undo work, and the preview stage is where they do it. For us this means a preview is a genuine experiment, not a release with a warning label, and planning as if it will become final unchanged is a bet.
3What a Preview Really Costs in Production
The cost is easy to underestimate. A class compiled with previews is tied to that exact JDK release, and no other JVM will load it, so every JDK upgrade forces a rebuild and possibly a rewrite. Organizations often stay on an LTS release for years and then jump, say from 21 to 25. Code using a JDK 21 preview cannot simply move: if the feature changed, it must be rewritten, and if it was withdrawn, as templates were, every use must be replaced before the upgrade can even compile.
Shared libraries make this much worse. A library that uses a preview forces every consumer to enable previews and to run exactly the same JDK release, so one team's experiment can block the upgrades of fifty services.
| Kind of code | Preview allowed? | Reason |
|---|---|---|
| Spikes, prototypes, learning repos | Yes | Thrown away or rewritten anyway |
| Internal tools and build scripts | Yes, with an owner | Few users, easy to change |
| Production services | No, except by exception | Blocks or delays JDK upgrades |
| Shared libraries and starters | Never | Forces the flag and JDK on all consumers |
4A Policy for a Large Organization
The policy I would set has four parts. First, preview features and incubator modules are welcome in experiments, prototypes and internal tools, because learning early is valuable and the cost of change there is small. Second, they are not allowed in production services or in shared libraries, and the build enforces that: the shared parent build fails if --enable-preview or an incubator module appears in a production module, so the rule does not depend on reviewers remembering it.
Third, there is an exception path for the rare case where a preview gives a large, measured benefit. The team writes a short proposal stating the feature, the gain, the owner and the plan for each JDK upgrade, and an architecture group approves it with an expiry date. Fourth, the policy is reviewed with every LTS release, because features that were previews last time are often final now, and then the rule simply stops applying to them.
- Is it a shared library or starter?YesNot allowedNoContinue
- Is it a production service?YesException process onlyNoAllowed
- Exception: measured benefit and owner named?YesApprove with an expiry and upgrade planNoRefuse; wait for the final feature
3 steps in order. Play them, or step through them one at a time.
5Staying Close to the Platform Without Betting on It
Forbidding previews in production should not mean ignoring them. A small group of interested engineers, often called Java champions inside the company, follows the JEPs that matter to us, tries previews in a sandbox repository and reports what they learn. Because previews exist for feedback, we should actually give it: concrete reports on the OpenJDK mailing lists, such as amber-dev for language features, about how a feature works on our code are exactly what the designers ask for.
We also run part of our CI against early-access JDK builds. That tells us months in advance which libraries or code will break on the next release, which is the other half of keeping upgrades cheap.
6When a Team Adopts a Preview Anyway
Sometimes a team has already shipped a preview, or has a strong case for one. Then the job is to make the cost visible and bounded. We estimate the migration work for each upcoming JDK upgrade and put it on the team's roadmap, we keep the preview code in a small module behind an interface so a rewrite touches as little as possible, and we pin the JDK version for that service explicitly so nobody upgrades it by accident. For string templates, a team that had followed this would have replaced a few dozen calls in one module with formatted() before moving to Java 25, a few days of work instead of an emergency.
7Follow-up questions
Are incubator modules the same as preview features?
They follow the same idea but cover different things. Preview features are language or JVM features enabled with --enable-preview. Incubator modules are APIs in modules named jdk.incubator.something, added with --add-modules, and they may change or move before becoming final. The Vector API has been an incubator module for many releases. The policy treats both the same way: experiments yes, production and shared libraries no.
Which preview features became final, and does that weaken the argument for caution?
Many did. Records, sealed classes, pattern matching for switch, virtual threads and text blocks all passed through previews and became final, sometimes with changes. That supports caution rather than weakening it: several changed between previews, and string templates show that withdrawal is a real outcome. Waiting for the final release usually costs only six months to a year, and an LTS adopter loses little because most previews finish before the next LTS.
How do you enforce the rule across hundreds of repositories?
Through the shared build configuration rather than through reviews. A rule in the parent Maven or Gradle build, for example a Maven Enforcer rule or a small Gradle check, fails the build of a production module when --enable-preview or an incubator module appears in the compiler or runtime arguments. Repository templates mark modules as production or experimental, and the exception list lives next to the rule, so an approved exception is visible and has an expiry date.
8Conclusion
In this answer, we saw that string templates were previewed twice and then withdrawn, which shows that Java treats previews as real experiments because final features are supported for decades. Preview code is tied to one JDK release, so in production it turns every upgrade into a rewrite, and in shared libraries it spreads that cost to every consumer. The policy we set allows previews in experiments and internal tools, forbids them in production services and shared libraries with build enforcement and a narrow exception process, keeps us close to the platform through tracking, feedback and early-access builds, and budgets migration cost when a team adopts a preview anyway.
Open with
The string templates story shows that previews are real experiments. They were previewed in JDK 21 and 22, the team decided the processor design was not right, and they removed them in JDK 23 rather than make them final.
Then, if they want more
Java does that because a final feature has to be supported for decades under a very strong compatibility promise, so they would rather be slow and correct than fast.
For an organization, the key fact is that preview code is compiled for one exact JDK release, so every upgrade forces a rebuild and maybe a rewrite, and if the feature is withdrawn the upgrade cannot even compile until the code is replaced.
In a shared library it is worse, because every consumer has to enable previews and match the JDK.
So my policy would be: previews and incubator modules are welcome in prototypes, spikes and internal tools; they are not allowed in production services or shared libraries, enforced by the parent build failing on --enable-preview; and there is a narrow exception process with a named owner, a measured benefit, an upgrade plan and an expiry.
I would keep a small group tracking the JEPs we care about, trying previews in a sandbox and giving feedback on the OpenJDK lists, and run some CI on early-access builds. If a team does adopt a preview, we isolate it in a small module, pin the JDK and put the migration cost on the roadmap for each upgrade.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21, Java 25, Java 14, 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.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API 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 "String templates were previewed in two releases and then withdrawn. What does this teach...": https://scrivio-interview-library.netlify.app/java/strings/8b4e2b8037/