Revisit the String template syntax

forax at forax at
Sat Apr 15 08:28:15 UTC 2023

----- Original Message -----
> From: "Tagir Valeev" <amaembo at>
> To: "Remi Forax" <forax at>
> Cc: "Guy Steele" <guy.steele at>, "Brian Goetz" <brian.goetz at>, "amber-spec-experts"
> <amber-spec-experts at>
> Sent: Saturday, April 15, 2023 9:48:14 AM
> Subject: Re: Revisit the String template syntax

> Hello,  Rémi!
>> JavaScript is a user of the ${} syntax but it's a fairly recent addition.
>> In Java, Maven, Gradle through their lineage to Apache Ant, in fact, all
>> projects using the apache common-text StringSubstitutor (or the much older
>> StrSubstitutor) are using the ${} syntax since a very long time. All Java
>> developers are familiar with this syntax for string interpolation.
>> So for a lot of Java developers, the syntax \{} feels alien to Java in
>> comparison. So yes, you have to escape the $ sign, you have to tweak the lexer
>> but, in my opinion, it's a case where familiarity in the whole ecosystem trumps
>> local rationalization.
> To me, this is actually an argument against ${}. With \{}, the users
> will have a clear difference between language-supported interpolation
> and external library interpolation. I can imagine that in some cases,
> you may need to use both. For example, imagine that you are generating
> build.xml or pom.xml and want to store strings containing ${...} as is
> without interpolating right now, because they refer to the properties
> defined in that file. However, you want to interpolate eagerly some
> other parts of these strings using Java string interpolation.
> Something like STR."${project.basedir}/build/\{generateTempDirName()}/".
> You can easily combine two approaches with \{} escapes. It would be
> much harder and much more error prone to create such templates if the
> same syntax was used for both Java and external interpolation.

It's not really harder, you escape the first dollar-sign,

> I think that distinguished interpolation syntax, which is rarely used in other
> contexts, is actually an advantage. People will get used to it.

The real question is more, do we want two syntax for conceptually the same thing or not ?

Here is an example with an annotation,

  class SpringBean {

      private String myproperty;

      public void foo() {
          System.out.println(STR."myproperty: ${myproperty}");

> With best regards,
> Tagir Valeev


More information about the amber-spec-experts mailing list