There are two important differences in arrays compared to generic collections.
First, the array is covariant, whereas generics are immutable. The so-called covariant refers to: if the Sub class is a subtype of the Super class, then the array type sub[] is the subtype of super[], which is
That sub[] Array instances can be assigned to the super[] array type variable. Conversely, generics are immutable, so list<sub> and list<super> do not have subtypes and super-type relationships. Other words
You cannot assign a arraylist<sub> instance to a variable of type arraylist<super>.
Second, the array is materialized. As a result, arrays will know and check their element type constraints at run time. If you attempt to save an object of type string in a long array, compile without error.
But running will throw a arraystoreexception exception. Generics, by contrast, are implemented by erasing. So generics simply harden their type information at compile time, and at run-time
Discard their element type information. Erasing is to make generics interoperable with code that does not use generics.
Because of the fundamental differences above, arrays and generic collections do not mix well. such as: New list<e>[], new list<string>[] are not legal.
25th: Generic sets take precedence over arrays