According to this entry in the Java Generics FAQ, there are some circumstances where a generic method has no equivalent non-generic method that uses wildcard types. According
If the type parameter were a wildcard-parameterized type, then the problem does not occur:
Class> foo = null;
f(foo);
g(foo);
I think this is almost certainly a weird case arising out of the fact that the type of the class literal is Class
, and so the type parameter in this case (ArrayList
) is a raw type, and the subtyping relationship between raw ArrayList
and wildcard-parameterized ArrayList>
is complicated.
I haven't read the language specification closely, so I'm not exactly sure why the subtyping works in the explicit type parameter case but not in the wildcard case. It could also very well be a bug.