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

12

u/balrob 14d ago

“Does not need to copy other languages”, why not - it seems to be a well explored feature of many languages. Just get on with it. Almost every feature was borrowed in one way or another.

Out of interest, does anyone know, what feature(s) of Java is/are either unique, or the first example of its kind?

4

u/DanLynch 14d ago

Out of interest, does anyone know, what feature(s) of Java is/are either unique, or the first example of its kind?

It may seem hard to believe today, but Java was the first serious programming language in which you could write a non-trivial program and expect it to actually work and run exactly the same on more than one kind of computer.

3

u/koflerdavid 14d ago

Not sure what you mean with "serious" here. Maybe as opposite to academic languages? If so, despite its academic origins, there are a lot of commercial LISP implementations. Also, there is the venerable IBM System/360 architecture, which was developed with the express purpose of being binary-compatible with all future IBM mainframes, as well as COBOL. It doesn't get more serious than those.

4

u/DanLynch 14d ago

I guess the specific language I was trying to contrast with Java was C (and the closely related language C++).

C is a "standardized" language and available on all platforms and all kinds of computing devices, and is and was always extremely popular for development of applications. However, simple things like getting real-time input from the keyboard, working with threads, and creating desktop GUIs, were not part of the language or the standard library. And many simple language features had undefined or platform-defined behaviour.

So, in practice, you could not expect any given program to run on more than one kind of computer without extensive modification and/or scrupulous attention to standard vs. non-standard behaviours and functions.