From Effective Java by Joshua Bloch,
Cov
My take: When code is expecting an array A[] and you give it B[] where B is a subclass of A, there's only two things to worry about: what happens when you read an array element, and what happens if you write it. So it's not hard to write language rules to ensure that type safety is preserved in all cases (the main rule being that an ArrayStoreException
could be thrown if you try to stick an A into a B[]). For a generic, though, when you declare a class SomeClass
, there can be any number of ways T
is used in the body of the class, and I'm guessing it's just way too complicated to work out all the possible combinations to write rules about when things are allowed and when they aren't.