Question about casting a class in Java with generics
- by Florian F
In Java 6
Class<? extends ArrayList<?>> a = ArrayList.class;
gives and error, but
Class<? extends ArrayList<?>> b = (Class<? extends ArrayList<?>>)ArrayList.class;
gives a warning.
Why is (a) an error? What is it, that Java needs to do in the assignment, if not the cast shown in (b)?
And why isn't ArrayList compatible with ArrayList? I know one is "raw" and the other is "generic", but what is it you can do with an ArrayList and not with an ArrayList, or the other way around?