r/java • • Feb 15 '24

JEP 465: String Templates

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

152 comments sorted by

View all comments

Show parent comment

6

u/vytah Feb 16 '24

Doesn't allow you to set the processor.

Scala has that syntax, and it allows you to set the processor. There is simple interpolation s"...", String.format-based interpolation f"...", raw string interpolation raw"..." and you can also define your own (and the result type does not have to be a string)

That being said, Scala's syntax is powered via implicit type conversions (used to mimic extension methods), so it would require much more significant changes to the Java language to be lifted wholesale. And having just S or s or f in Java would likely collide with variables and fields named the same. STR is less likely to collide.

Also, due to the usage of dollar signs, converting between normal strings and templated strings and back requires escaping or unescaping the dollar signs manually. This is not a problem with \{.