RFR of JDK-8285932 Implementation of JEP-430 String Templates (Preview)
Jim Laskey
james.laskey at oracle.com
Thu Nov 17 12:57:17 UTC 2022
I corrected before inserting.
On Nov 16, 2022, at 7:41 PM, John Rose <john.r.rose at oracle.com<mailto:john.r.rose at oracle.com>> wrote:
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/20221117/60bff773/attachment.htm>
More information about the compiler-dev
mailing list