Update on String Templates (JEP 459)
Mark Reinhold
mark.reinhold at oracle.com
Tue Mar 19 18:19:47 UTC 2024
2024/3/19 13:41:37 -0400, guy.steele at oracle.com:
> Actually, Brian, I _am_ going to nitpick your use of the name “join”
> here for all three of those methods, because, given the comments, they
> do very different things; the first two do “string interpolation” on a
> single template (and in the process convert the values in the template
> to strings) whereas the last combines multiple templates into a single
> template (but does not convert any of the values to strings).
>
> Moreover, the existing `join` method of String does yet a different
> operation: concatenate a sequence of strings, using a given delimiter
> string (repeatedly, if necessary) as a separator. So I think “join”
> was a particularly infelicitous choice of name for these three
> examples.
Agreed.
> Here I set forth your three examples with new names that are related
> to those already used in the existing preview implementation of
> StringTemplate in JDK 21 (and JDK 22—I just checked). I do this not to
> suggest that these other names should be used, but only in the hopes
> of reducing confusion as we begin this discussion. Later we can decide
> whether the names “process” and “interpolate” and “combine” should be
> changed (possibly all into the same single name).
>
> // on String
> static String process(StringTemplate) // previously STR
>
> // on StringTemplate
> String interpolate() // STR, instance/suffix version
> static StringTemplate combine(StringTemplate...) // + for string templates
Maybe I’m missing something, but: Why do we need both `String::process`
and `StringTemplate::interpolate`? What are the use cases?
- Mark
More information about the amber-spec-experts
mailing list