Video in progress

The team wants to use preview features (--enable-preview) in production code. How do you decide?

Usually no. A preview API can change or be removed entirely in the next release (String templates were a preview in Java 21-22 and were removed in 23), and the bytecode only works on exactly that JDK version. Allow it for experiments, internal tools and prototypes; for production, wait for it to become final.

📖 Answer

Preview means "almost ready, we need feedback", not "stable". The technical consequences:

  • a .class file compiled with --enable-preview is marked with a special minor version. Only a JDK of exactly that feature version can run it: preview code built on Java 21 won't load on Java 22. So every JDK update forces a recompile.
  • Every library passes that requirement along: if you add a library that uses preview, you're tied to it too.
  • The semantics change. Examples: String templates (JEP 430) were a preview in Java 21-22 and were removed completely in Java 23; some forms of record patterns changed before they became final; unnamed classes and instance main were redesigned several times.
  • Tools (IDEs, static analysis, coverage, APM agents) support preview syntax late.

Incubator modules (jdk.incubator.*, for example the Vector API) are a separate category: an API, not a language feature, but they change too.

A decision framework:

Place Allowed
A production service No
An internal CLI, a script, a one-off tool Yes, with the JDK version pinned
A spike, a prototype, a tech talk Yes
An open-source library No

If the business reason is strong (for example, virtual threads would have given a very big benefit during their preview), the conditions are: the feature is isolated in one module, the JDK version is pinned in the image, and there's an owner and a deadline for moving to the final version.

Instead of just saying "no" to the team, give them a channel: a sandbox repo for trying out previews, and sending the results to the OpenJDK mailing list, which is also part of a staff engineer's job. When the feature becomes final (usually after 1-2 releases), adopting it is quick and safe.