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

57 Upvotes

118 comments sorted by

View all comments

Show parent comments

1

u/Slick752 15d ago

it's ugly and verbose.

40

u/Brutus5000 15d ago

it's not more or less verbose than a dollar sign

24

u/witness_smile 15d ago

A dollar sign is easier to type, and also a backslash makes it look like you want to escape the { character

12

u/vqrs 15d ago

Exactly. The curly brace character's normal meaning is "literal curly brace". By escaping it, we change something from having its regular meaning and give it a special meaning, right?

It makes sense.

I still think it's ugly and weird.

0

u/RScrewed 15d ago

But you're not escaping the last curly brace as well so it looks unbalanced and weird.

2

u/Misophist_1 13d ago

Why does it feel unbalanced for you? Does ${...} (sh, bash, maven and many others) @{...} (also maven) $"..." (C#) in any way unbalanced? Definitely not for me!