<div dir="ltr"><div>As I see values are always Object. However, for type-safety it would be good to have bounded types:</div><div><div style="background-color:rgb(255,255,255);color:rgb(8,8,8)"><pre style="font-family:"JetBrains Mono",monospace;font-size:9.8pt"><span style="color:rgb(0,51,179)">public interface </span>StringTemplate<V> {<br> List<V> values();<br> ...<br>}</pre></div></div><div><br></div><div>E.g. a Json template should require values to be <code>JSONObject</code>. In this case it would be possible to compose fragments with type-safety like this:</div><div><pre><code>String name =</code><code> "Joan Smith"</code><code>;<br>String phone = </code><span style="color:rgb(0,51,179)">null</span><code>;<br></code><span style="color:rgb(0,51,179)">boolean </span><code>residential</code><code> = </code><span style="color:rgb(0,51,179)">true</span><code>;</code></pre><pre><code>JSONObject address = JSON."""</code><code><br> {
"residential</code><code>": \{</code><code>JSON.primitive(</code><code>residential</code><code></code><code>)},
"postcode": \{</code><code></code><code>JSON.primitive(</code><code>postcode</code><code>)}
}
</code><code> """;</code></pre><div></div><div></div><pre><code>JSONObject doc = JSON."""
{
"name": \{</code><code>JSON.primitive(</code><code>name)},
"phone": \{</code><code></code><code>JSON.primitive(</code><code>phone)},
"address": \{address}<br> }
""";</code></pre></div><div><br></div><div>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 <code class="gmail-lang-cs"><span>AppendFormatted</span></code> here <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/improved-interpolated-strings">https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/improved-interpolated-strings</a></div><div><br></div><div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">WBR, Anatoly.</div></div></div>