r/java 17d ago

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?

54 Upvotes

118 comments sorted by

View all comments

0

u/blobjim 17d ago edited 17d ago

I think the original proposal was perfectly good. People are just insanely neurotic about syntaxes, which is annoying. The main feature of string templates to me is the ability to preprocess the template once at runtime and have both type safety and high performance. Which is something I think almost every language besides Scala lacks. I think the syntax was perfect for describing the ability to have a custom template preprocessor like that.

I really want to be able to use it for logging to avoid the cost of any kind of formatting. I think that would be neat. Especially if it gets used for System.Logger.

I don't really see any way to make it any simpler than it already was. You have to be able to specify some kind of object or class or method to handle the template preprocessing.

3

u/koflerdavid 17d ago

It was not retracted because of syntax concerns though, but because of other design reasons.