Update on String Templates (JEP 459)
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Mar 13 15:40:12 UTC 2024
I don’t disagree.
After some more pondering, while text blocks and string literals clearly
have a lot of overlap - e.g. they both end up being String objects,
that’s not the case with string templates.
So, if the following assignment fails:
|String s = "foo \{bar}"; |
One might argue that perhaps the syntax should be “more obviously
different”.
Maurizio
On 13/03/2024 14:48, Archie Cobbs wrote:
> Consider how we handle float vs. double literals. They overlap for
> 32-bit values, which is very convenient, but you can also "force" a
> narrower interpretation by adding an "f" suffix. That seems like
> pretty much the best of both worlds to me.
>
> So is this an analogous situation? Then we'd allow a StringTemplate
> literal to have an /optional/ "$" prefix:
>
> obj.takingString("abcd"); // ok - string
> obj.takingTemplate("abcd"); // ok - template
> obj.takingStringOrTemplate($"abcd"); // ok - template
> obj.takingStringOrTemplate("abcd"); // ok - string or template
> (personally I don't care)
> obj.takingString($"abcd"); // fail
> obj.takingTemplate($"abcd"); // ok - template
> obj.takingString("x = \{var}"); // fail
> obj.takingTemplate("x = \{var}"); // ok - template
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20240313/d77dc57a/attachment-0001.htm>
More information about the amber-spec-observers
mailing list