Some observations on JEP draft of Templated Strings and Policies

Remi Forax forax at
Sat Oct 16 22:57:51 UTC 2021

----- Original Message -----
> From: "Alejandro" <alxegod at>
> To: "jdk-dev" <jdk-dev at>
> Sent: Samedi 16 Octobre 2021 19:08:27
> Subject: Some observations on JEP draft of Templated Strings and Policies

> Hello,


> For some context, I am a simple fan of Java, as I don't even use it on
> my daily job, and have just recently started being an observer of it's
> development.
> Now, while browsing Reddit's r/java, I saw that JDK-8273943, Templated
> Strings and Template Policies (Preview), had been updated.
> I previously knew about the feature from, possibly, some posts in
> either GitHub or, but didn't know as many details until I
> read the JEP draft.
> Overall, I like the additions quite a lot and want to congratulate
> everyone's effort, but I had one observation, in particular with the
> usage of java.util.List.
> Let me quote the observations I posted on the Reddit thread:
>> I don't like the idea of TemplatedString having a dependency on java.util.List,
>> as it means that the latter would now be hard-coded into the language.
>> A more sensible solution would be any java.lang.Iterable, which is already
>> hard-coded into the language due to it's usage in for-each loops.
>> This one, as oposed to java.util.List is a very simple and concise interface.
>> From an implementor's point of view, they could continue using List::of.
>> From a consumer's point of view, they could still make use of for-each loops, or
>> construct a List easily, e.g. ts.values().forEach(myList::add).
> I am pretty sure that you've considered or discussed this topic
> before, but nonetheless I wanted to bring this into the mailing list.
> My reasoning is so that I can be directed to some past discussion on
> this, or to bring up the discussion if it hadn't popped up before.

This API is still in flux :)

Yes, it will be new for a class of java.lang to have an API dependency on java.util.List.

java.lang.String or java.lang.Throwable already have an implementation dependency (not an API dependency) on java.util.List and java.lang.invoke.MethodType has an API dependency on java.util.List. So i'm not sure there is a sacred line drawn in the sand since we have modules and java.lang and java.util are both inside the module java.base

When you write a template policy, you usually want to be able to rapidly checks if the number of arguments and the number of holes match.
There is not size() on Iterable. We can use an array instead, but it means a bunch of defensive copies will fly around.

Another solution is to not expose TemplatedString in the language and only be able to access it when you write a template policy,
in that case, TemplatedString can be moved into another package like java.lang.runtime.


> Best Regards,
> Alejandro


More information about the jdk-dev mailing list