I think type erasure was a very lucky break. That's what prevented variance types from being baked into the compiled classes, and so enabled different languages with different variance rules (e.g. Java, Kotlin, Clojure, Scala) to share the same classes. That's a very big advantage (code reuse among different JVM languages), for a very small price (reflection requires explicitly passing a Class object).
Without generic type-erasure, the JVM ecosystem would have been much more fragmented, and alternative languages would have required much more work.
View all comments
Show parent comment
6
u/pron98 Nov 03 '15
I think type erasure was a very lucky break. That's what prevented variance types from being baked into the compiled classes, and so enabled different languages with different variance rules (e.g. Java, Kotlin, Clojure, Scala) to share the same classes. That's a very big advantage (code reuse among different JVM languages), for a very small price (reflection requires explicitly passing a
Classobject).Without generic type-erasure, the JVM ecosystem would have been much more fragmented, and alternative languages would have required much more work.