Hacker News new | ask | show | jobs
by ootachi 5192 days ago
This doesn't seem to have anything to do with type erasure, does it? It's needed for type-safe generics. Even without type erasure, you still need type safety. If your generics are always covariant (like Dart's are), you break type safety.

I think the mistake the Java designers made here was going with use-site variance instead of definition-site variance.

1 comments

Yes, you're right. We're talking about variance when it comes to the "? extends, ? super" situation, not erasure. And you're also right the things would be better with definition-site variance.

On the other hand, sometimes I think an unsound type system with List<String> being a subtype of List<Object> would be better than what we have today, for pragmatic reasons. Of course, I think this makes me a non-type-theorist, as what I'm saying is considered heresy in some circles [1].

[1] http://lambda-the-ultimate.org/node/4377 (search for unsound).

But than you can never get anything from List<String>! Because you never know what type are you getting!

On the other hand, if your structure is immutable it would probably work.