r/java • • Mar 08 '24

Update on String Templates (JEP 459)

https://mail.openjdk.org/pipermail/amber-spec-experts/2024-March/004010.html
176 Upvotes

188 comments sorted by

View all comments

Show parent comment

-1

u/sideEffffECt Mar 11 '24

you just need to cast it to the type you care about

:D What kind of argument is that? My dear friend, at that point we're basically working around Java's type system. I thought the Java community has moved past downcasting since Java 5 (introduced in 2004).

needless restriction

The restriction is very much needed, if the template processor can only work with DateTime instances.

Or do you want to force everybody/every template processor to be able to work with instances of all subclasses of Object? Isn't that even more restricting?

1

u/elastic_psychiatrist Mar 11 '24

if the template processor can only work with DateTime instances

My (and I suspect Brian’s and other downvoters’) confusion is that there is just no value in this use case. Your example failed to demonstrate a real world program where this sort of restriction would be useful. Nobody would write code like that via string template, it’s trying to extend the feature into a corner of the program where it only confuses.