<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><div style="font-family: sans-serif;"><div class="markdown" style="white-space: normal;">
<p dir="auto">On 16 Nov 2022, at 11:10, Alex Buckley wrote:</p>
</div><div class="plaintext" style="white-space: normal;"><blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid #777777; color: #777777;"><p dir="auto">…
<br>
For example, the following code contains a template expression that uses the template processor `RAW`, which simply yields the `StringTemplate` passed to it:</p>
<p dir="auto">int x = 10;
<br>
int y = 20;
<br>
StringTemplate st = RAW."\{x} + \{y} = \{x + y}";
<br>
List<String> fragments = st.fragments();
<br>
List<Object> values = st.values();</p>
<p dir="auto">`fragments` will be equivalent to `List.of(" + ", " = ")` and `values` will be the equivalent of `List.of(10, 20, 30)`.
<br>
…
<br>
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()`.</p>
</blockquote></div>
<div class="markdown" style="white-space: normal;">
<p dir="auto">And yet, in the example given above, the list of fragments <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">List.of(" + ", " = ")</code> is one element <em>smaller</em> than the list of values <code style="margin: 0; padding: 0 0.4em; border-radius: 3px; background-color: #F7F7F7;">List.of(10, 20, 30)</code>. 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.</p>
</div></div></body>
</html>