3 ms·
Occasionally it is really useful to be able to do something like `new T()`. Without reified generics that is not possible.
by positr0n 1y ago
Occasionally it is really useful to be able to do something like `new T()`. Without reified generics that is not possible.
- mrkeen 1y agonew T? What's wrong with the old one? Jokes aside, what's the use case for not knowing what T is until runtime?
- chuckadams 1y agoPretty much all polymorphism works by not knowing the concrete type til runtime. If you have an Animal reference to a Dog instance, any method you call on it is resolved at runtime, because the reference knows the type. Reified generics do the same for type parameters, whereas erased types are only used for type checking at compile time.
- mrkeen 1y agoNah I think I'd just prefer to figure out the types in type-checking phase, then erase and get on with things. I don't buy that most polymorphism is dynamic. No example of 'new T()' (which wouldn't be improved by static typing was given) so I got nothing else to say.