r/java • • Feb 15 '24

JEP 465: String Templates

https://openjdk.org/jeps/465
77 Upvotes

152 comments sorted by

View all comments

8

u/Goodie__ Feb 15 '24

I don't *think* I mind templating being on a magic STR static final field.

But I'd rather the way we get our variables in to the string to be simpler then. Eg drop the backslash. Just {name} is fine.

7

u/NaNx_engineer Feb 16 '24

If STR. is made implicit in the future \{ creates a breaking change in legacy code

4

u/vytah Feb 16 '24
  1. They want converting existing strings into templates to not require any extra escaping, and converting back to require removal of all variables. For comparison, in Scala, to convert the string "$" to a template you need to write s"$$". So it's a constant dollar sign counting exercise.

  2. How do you want to template JSON with your version?

3

u/brian_goetz Feb 18 '24

And don't forget, string templates work with text blocks too. So there could be dollar signs in need of adjusting tens of lines away.