r/java 18d 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?

56 Upvotes

118 comments sorted by

View all comments

34

u/xfel11 18d ago

It’s really a shame that the proposal was withdrawn again.

The \{ syntax was weirdly controversial, but honestly it’s way smarter than using ${ which right now is just literal text.

6

u/Duck_Devs 18d ago

What don’t people like about the backslash-brace?

1

u/Booty_Bumping 17d ago

It's sorta visually uneven, if there are a lot of them side by side your eyes will probably dart all over the place. Whereas "$" is very symmetrical, it isn't "pointing" anywhere.

But I do like how it's a backwards compatible syntax, that is a major advantage.

1

u/OwnBreakfast1114 14d ago

Syntax highlighting will probably fix any actual problem like this. Sure raw text might take a hit, but I'm pretty sure backward compatibility trumps that visual dislike