Re:Type erasure and reification
by int_19h on Friday December 07, 2018 @05:01PM
(#18632093)
Overloading is orthogonal to all this. The reason why it can't implement two generic interface instantiations on the same class is not because method names clash (even sans overloading, the language can provide means to implement interface methods with differently-named class methods - e.g. C# does that). It's because at runtime, once you erase the type parameter, there's only one interface type, and you cannot implement it twice.
The reason why OCaml doesn't have this problem is because it doesn't have runtime type checks of the kind Java does - there's no "instanceof", and there's no downcasts or cross-casts. So it doesn't need reified types, because it doesn't allow the programmer to perform operations that expose the difference. So, for OCaml, type erasure is a sound approach that is consistent with its type system. But not for Java, because of casts and "instanceof".
The reason why OCaml doesn't have this problem is because it doesn't have runtime type checks of the kind Java does - there's no "instanceof", and there's no downcasts or cross-casts. So it doesn't need reified types, because it doesn't allow the programmer to perform operations that expose the difference. So, for OCaml, type erasure is a sound approach that is consistent with its type system. But not for Java, because of casts and "instanceof".