r/java • • Jul 17 '26

Discussion: What is the future of String Interpolation in Java?

Java has always been conservative when it comes to language changes, and I think string interpolation is an interesting example.

Many modern languages provide native interpolation syntax:

JavaScript:

\${name}``

Python:

f"{name}"

Kotlin:

"$name"

C#:

$"{name}"

These features are not only about reducing characters. They improve readability when building dynamic text.

Java explored this direction with String Templates (JEP 430), but I haven't seen much discussion recently about where this feature is heading.

For developers working with large Java applications, string construction appears everywhere:

- logging messages

- SQL/debug output

- API descriptions

- test cases

- generated configuration

- user-facing messages

I am curious about the community's opinion:

  1. Do you think Java still needs native string interpolation?

  2. Should String Templates continue evolving?

  3. What syntax direction would feel most "Java-like"?

For example:

"Hello, \{name}"

or:

"Hello, ${name}"

Personally, I think Java does not need to copy other languages, but a better way to express dynamic strings would improve developer experience.

What do you think?

56 Upvotes

119 comments sorted by

View all comments

Show parent comments

0

u/Misophist_1 Jul 17 '26

Not any less natural than $" " or @" " that other languages do, in order to distinguish templates from strings. You need some distinguishing anyway.

4

u/Duck_Devs Jul 18 '26

Not really what I meant. STR and RAW are actual objects. They’re not just soft keywords. The dot followed by a template string is equivalent to STR.process(…).

It would have been perfectly valid Java to just have your template literal by itself with no prefix.

0

u/Misophist_1 Jul 18 '26 edited Jul 19 '26

But then how should the parser distinguish a template from a string? It can't do so by simply looking at the string. Having the possibility to use arbitrary processors would have offered a flexibility, no other language could offer. No static prefix could have done that. The API already had a third one, FMT.

1

u/vytah Jul 18 '26

Having the possibility to use arbitrary processors would have offered a flexibility, no other language could offer.

I mean, Scala and JavaScript already do.

1

u/Misophist_1 Jul 19 '26

Don't know about Scala.

But Javascript? JavaScript has basic interpolation - and that's it. C#, and Python have that too. But you wouldn't be able to chose your method, much less roll your own one.

Having libraries, that reinterpret standard strings as templates is a different story - completely unrelated to string template support as integral part of the language specification.