That has nothing to do with the type parameter. This works as well:
List<String> list = null;
Connection c = (Connection) list;
It's possible because List
is an interface type. It would be possible for the list reference to hold an object that both implements the List
interface and is also a Connection
(whatever that is, class or interface), and for which the cast therefore works.
Thus, since the cast could work, the compiler allows it. It will only reject casts that are theoretically impossible, i.e. which involve concrete types in separate inheritance hierarchies:
JComponent c = null;
ArrayList l = (ArrayList) c;
You can look up the exact rules for what types of casts are legal at compile time in the Java Language Specification - it's about 30 lines of dense language lawyering.