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.