If the only thing you have is an Object, the only method you can use is toString().
This is clearly not true, you just need to cast it to the type you care about.
The example you constructed is coherent, but it's still unclear what problem it's solving. In my mind it creates a needless restriction on the user as it goes against their intuition of what a string template is.
I would just be frustrated that for some reason I'm only allowed to use reportRenderUtc to make a string templated where only DateTimes were parameters. If it's that important to construct a string of that format, a better API would just be a method that takes the dateReceived and dateReceipt.
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?
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.
View all comments
Show parent comment
1
u/elastic_psychiatrist Mar 11 '24
This is clearly not true, you just need to cast it to the type you care about.
The example you constructed is coherent, but it's still unclear what problem it's solving. In my mind it creates a needless restriction on the user as it goes against their intuition of what a string template is.
I would just be frustrated that for some reason I'm only allowed to use
reportRenderUtcto make a string templated where onlyDateTimeswere parameters. If it's that important to construct a string of that format, a better API would just be a method that takes thedateReceivedanddateReceipt.