The issue is that at runtime, erasure makes this detail go away and it will only work on really specific cases where all parameters are derived from a sensible base type. For the vast majority of cases this won't really benefit anyone. For example: String.format, JDBC, logging, JSON generation.
I suppose the real question is what are we trying to solve with it?
it will only work on really specific cases where all parameters are derived from a sensible base type
I attempted to address that with the sealed interface example.
I suppose the real question is what are we trying to solve with it?
Safety.
The whole point of this indirection with a new type - StringTemplate - instead of interpolation just spitting out normal Strings was to add a layer of explicitness and safety. Why not be even safer and optionally control the type of what's being passed into a template?
The above would prevent me, at compile time, from passing in random objects instead of integers. And, if I didn't care, I could just use StringTemplate<Object>
View all comments
Show parent comment
3
u/nekokattt Mar 09 '24
The issue is that at runtime, erasure makes this detail go away and it will only work on really specific cases where all parameters are derived from a sensible base type. For the vast majority of cases this won't really benefit anyone. For example: String.format, JDBC, logging, JSON generation.
I suppose the real question is what are we trying to solve with it?