|
|
|
|
|
by zak_mc_kracken
4082 days ago
|
|
> It'd be REALLY nice if I could just say "Hey handler, what's your generic type? Is the message I just got an instanceof your generic type? No, it wouldn't be nice, it would be unsafe. If one day you end up adding a new type in your container, you need to update your runtime check as well or your code will fail in mysterious ways. Erasure keeps you honest by asking you to think carefull about the types so that they can be checked by the compiler, and once the compiler has done this verification, you are guaranteed that your code will work. Any language feature that encourages the use of reflection , such as reification of types, should not be supported by a language that wants to claim to be sound. |
|
If the compiler provides a couple things:
such that TypeRepr cannot be generated (e.g. faked) by users, typeOf is guaranteed to be genuine, and (this is the hardest) such a thing doesn't violate parametricity then you can use that interface to write which is guaranteed to only allow the coercion when `a` and `b` actually happen to be the same type.