[JEP 430] StringTemplate should be generic?
Anatoly Kupriyanov
kan.izh at gmail.com
Wed Aug 2 23:30:22 UTC 2023
As I see values are always Object. However, for type-safety it would be
good to have bounded types:
public interface StringTemplate<V> {
List<V> values();
...
}
E.g. a Json template should require values to be JSONObject. In this case
it would be possible to compose fragments with type-safety like this:
String name = "Joan Smith";
String phone = null;
boolean residential = true;
JSONObject address = JSON."""
{
"residential": \{JSON.primitive(residential)},
"postcode": \{JSON.primitive(postcode)}
} """;
JSONObject doc = JSON."""
{
"name": \{JSON.primitive(name)},
"phone": \{JSON.primitive(phone)},
"address": \{address}
}
""";
There are some good ideas implemented in C# for type-safety, e.g. it allows
to have different overloads for different types for avoiding run-time type
matching. See AppendFormatted here
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/improved-interpolated-strings
--
WBR, Anatoly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230803/f2281632/attachment.htm>
More information about the amber-dev
mailing list