RFR of JDK-8285932 Implementation of JEP-430 String Templates (Preview)

John Rose john.r.rose at oracle.com
Wed Nov 16 23:41:16 UTC 2022


On 16 Nov 2022, at 11:10, Alex Buckley wrote:

>> For example, the following code contains a template expression that 
> uses the template processor `RAW`, which simply yields the 
> `StringTemplate` passed to it:
>
> int x = 10;
> int y = 20;
> StringTemplate st = RAW."\{x} + \{y} = \{x + y}";
> List<String> fragments = st.fragments();
> List<Object> values    = st.values();
>
> `fragments` will be equivalent to `List.of(" + ", " = ")` and `values` 
> will be the equivalent of `List.of(10, 20, 30)`.
>> To preserve the semantics of string templates and text block 
> templates, the list returned by `fragments()` must be one element 
> larger than the list returned by `values()`.

And yet, in the example given above, the list of fragments `List.of(" + 
", " = ")` is one element *smaller* than the list of values `List.of(10, 
20, 30)`.  The example is wrong.  It’s worth a note in the doc that if 
an interpolated expression begins and/or ends the template, there will 
be a zero length fragment at the beginning or end of the fragments list.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20221116/1e466640/attachment-0001.htm>


More information about the compiler-dev mailing list