3 ms·
It's in fact not type erasure that "rears its ugly head", but actually that Java's type system is not expressive enough, which is why developers end up relying
by bad_user 9y ago
It's in fact not type erasure that "rears its ugly head", but actually that Java's type system is not expressive enough, which is why developers end up relying on reflective capabilities.
There's something seriously wrong with the type system when you want "instanceOf T" checks or "new T".
- kelnos 9y agoIf you don't have/want "new T", how do you ever create an instance of anything?
- chii 9y agoThe in this context is a variable, not a concrete type.
- barrkel 9y agoDid you mean: "The T in this context..."? Instantiating a generic type is like a function call at compile time, where the type arguments are substituted for type parameters in the body of the generic type. It's a variable at compile time, but it's a concrete type at runtime for any version of the code that can execute.
- barrkel 9y agoThere's nothing wrong with doing 'new T' in a generic method or class body. It requires a constraint on the type variable is all: that some constructor with a specific parameter list is available.