Question about casting a class in Java with generics
Posted
by
Florian F
on Programmers
See other posts from Programmers
or by Florian F
Published on 2014-05-26T21:46:53Z
Indexed on
2014/05/26
21:59 UTC
Read the original article
Hit count: 485
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?
© Programmers or respective owner