3 ms·
> Even if you constrain the type to be something you know is a class, it won't work. [1] Oh yes, I'm not saying it's possible to do this in Java, AFAIK you're
by masklinn 11y ago
> Even if you constrain the type to be something you know is a class, it won't work. [1]
Oh yes, I'm not saying it's possible to do this in Java, AFAIK you're right that it's not, I'm saying I'm not sure it's because of type erasure, at least type erasure on its own.
- scott_s 11y agoI think it is. As far as Java is concerned, T is Object in that context. It can't generate code for "allocate a T" because Foo only actually operates on Objects, not Ts. That is, there will be one version of Foo, and that version will generate code to interact with Objects, not Ts. It can't allocate a T because the type of T is erased from Foo. That is type erasure.