Update on String Templates (JEP 459)

Archie Cobbs archie.cobbs at gmail.com
Mon Mar 11 16:07:58 UTC 2024


On Mon, Mar 11, 2024 at 9:37 AM Remi Forax <forax at univ-mlv.fr> wrote:

> I vote for making string templates explicit.
>

Caveat: I've been following this discussion only loosely so I'm likely to
say something stupid/ignorant/redundant; if so please ignore.

But I am tending to agree with Remi. The recent simplifications Brian
described are a definite improvement, but now we're left with a new
question:

What is the advantage of having the language literals for String and
StringTemplate look so confusingly similar?

Reversing that question, I'm not seeing the big downside of having a simple
prefix for literals like this:

    var s = "this is a string";
    var st1 = $"this is a (degenerate) template";
    var st2 = $"this is also a \{template}";
    var x = "this is a \{lexical_error}";
    myobj.someOverloadedMethod($"this is definitely a template");
    myobj.someOverloadedMethod("this is definitely a string!");     // no
need to consult javadoc here

Seems like the trade-off is straightforward:

Cost: one character
Benefit: instant disambiguation clarity in the developer's mind

At least, it makes the whole API design/overload question straightforward.

Put another way, StringTemplates are a cool new language feature, and as
such it seems like they deserve a "first-class" allotment in the syntax of
the language.

-Archie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20240311/2cad84cc/attachment.htm>


More information about the amber-spec-experts mailing list