Update on String Templates (JEP 459)
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Mar 14 23:44:20 UTC 2024
On 14/03/2024 22:36, Robbe Pincket wrote:
> (I’m not a big fan of `TEMPLATE"Foo: \{bar}"` either as it’s just so
> much longer than `"Foo: " + bar`)
Note that when I suggested TEMPLATE as a prefix I was obviously not
being super serious :-)
Let's do a test (bear with me). Let's assume the two prefixes were S and
T (not saying I like them, just trying them out for size). Let's also
assume there's no conversion. Then your examples become:
```
String s1 = "test" // still a string literal
StringTemplate st2 = T"test" // allowed, constant strings can be
implicitly converted to templates
StringTemplate st3 = "Foo: \{bar}" // Simple string template
String s4c = S"Foo: \{bar}" // short for String.of("Foo: \{bar}")
```
I think that's not too bad? (please don't focus too much on the letters).
In the sense: the rare cases (st2) has a prefix. And the operation we
want explicit (s4c) also has a prefix. Everything else is fine.
Control question #1: does the conversion here change things much? Or,
are we reaching for conversions just to have something "shorter" ?
Control question #2: let's now assume that S and T were spelled (String)
and (StringTemplate), respectively. How do we feel about this?
```
String s1 = "test" // still a string literal
StringTemplate st2 = (StringTemplate)"test" // allowed, cast from
constant string to template
StringTemplate st3 = "Foo: \{bar}" // Simple string template
String s4c = (String)"Foo: \{bar}" // allowed, cast from template back
to String (interpolation)
```
Maurizio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20240314/6a70095a/attachment-0001.htm>
More information about the amber-spec-observers
mailing list