String templates: the one that was withdrawn

Java 21 Course · lesson 10 of 15 · 4 min read

Previewed in 21, previewed again in 22, then pulled entirely - a useful lesson about preview status.

Open this lesson in the learning hub

Key points

  • String templates promised safe interpolation: STR."Hello \{name}", with processors for SQL and HTML.
  • The point was injection safety - a processor could escape values instead of blindly concatenating.
  • It previewed in 21 and 22, then was removed in Java 23 while the design was reconsidered.
  • That is exactly what preview means: shipped for feedback, explicitly not a compatibility promise.
  • The practical lesson - never build production code on a preview feature you cannot afford to rewrite.

Preview features can be withdrawn - string templates is the case study, so treat --enable-preview as a warning.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Java 21 Course course, and every lesson in it is listed on the Java 21 Course contents page.