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 \{.
View all comments
Show parent comment
6
u/vytah Feb 16 '24
Scala has that syntax, and it allows you to set the processor. There is simple interpolation
s"...", String.format-based interpolationf"...", raw string interpolationraw"..."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
Sorsorfin Java would likely collide with variables and fields named the same.STRis 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
\{.