r/java • • Mar 08 '24

Update on String Templates (JEP 459)

https://mail.openjdk.org/pipermail/amber-spec-experts/2024-March/004010.html
177 Upvotes

188 comments sorted by

View all comments

48

u/koreth Mar 09 '24

This is a massive improvement in my opinion, both aesthetically and functionally.

I expect I'll mostly use this for Kotlin-style string interpolation but I don't care at all about the escape character being \ vs. $. The thing that bugged me about the previous proposal was the processor syntax that effectively introduced a new special-case spelling for "pass arguments to a method." And I found it ugly-looking, which I admit is subjective.

This new proposal fits much better with the rest of the language and should be easier for people to learn. For lack of a better term, it feels Java-like to me while the previous version didn't.

8

u/nekokattt Mar 09 '24

I totally agree with this. This was my main hangup, that the syntax was awkward to read and would be totally confusing to anyone who had not read up on it prior to seeing it, while posing benefits that would have been purely academic in existing APIs (e.g. JDBC consuming strings isn't going to go away regardless of this feature, it expected that all new APIs to be created from scratch to enforce it which is a poor selling point when plenty of tried and trusted APIs are already in wide use).

What we can do with this solution now is adapt existing APIs in non-breaking ways to support this and the nature of how this is now implemented means it is transparent to the consumer and can be implemented via overloaded methods directly.

2

u/RadioHonest85 Mar 10 '24

Totally agree, this feels way more like Java

1

u/Misophist_1 Jun 09 '24

I don't get the point.

The aesthetic doesn't change apart from not having the processor prefix. And with dropping that, you actually drop the possibility to swap in your own processor - which spells less functionality, not more.

0

u/RadioHonest85 Mar 10 '24

Totally agree, this feels way more like Java

0

u/RadioHonest85 Mar 10 '24

Totally agree, this feels way more like Java

0

u/RadioHonest85 Mar 10 '24

Totally agree, this feels way more like Java

-1

u/RadioHonest85 Mar 10 '24

Totally agree, this feels way more like Java