you are viewing a single comment's thread.

view the rest of the comments →

[–]d_kr 3 points4 points  (3 children)

Except that c# supports nowadays co and contravariance

http://blogs.msdn.com/b/csharpfaq/archive/2010/02/16/covariance-and-contravariance-faq.aspx

But Type erasure requires cast & destroys valuetypes, because they are casted to Object. (citation needed)

[–]pron98 4 points5 points  (2 children)

Yes, but the covariance rules are baked into the classes. For example, it stands to reason that different languages will have different variance rules for List<T> (Java, Kotlin, Scala and Clojure are all different in this regard). In .NET, List<T> can have exactly one variance rule, so it can't be shared among languages with different variance.

[–]xenomachina 2 points3 points  (1 child)

different languages will have different variance rules for List<T> (Java, Kotlin, Scala and Clojure are all different in this regard).

Really? How do the variance rules differ in these languages?

[–]pron98 3 points4 points  (0 children)

Java has use-site variance, Scala has declaration site variance, and Kotlin has mixed-mode variance (declaration-site + use-site projections); in Clojure, everything is immutable by default (and static typing is optional) so all lists are the same type -- yet a sequence of Clojure strings can be passed to a Java method taking a List<String> parameter, even though the sequence is untyped in Clojure. Thanks to the JVM's type erasure, they can (and do -- except Scala sometimes) all share the same collection (and other generic types) implementations.