Re: class array in jdk1.5
cell wrote:
The original line is:
Class[] cls={String.class,String.class,Integer.class};
and the warning is:
Class is a raw type. References to generic type Class<T> should be
parameterized.
However, I cannot solved it. I have tried
Class<Object>[] cls={String.class,String.class,Integer.class};
it does not work.
Arne Vajh?j wrote:
Try:
Class<?>[] cls = ...
Brian Goetz's excellent articles, "Going Wild with Generics", Part 1
<http://www.ibm.com/developerworks/java/library/j-jtp04298.html>
and Part 2
<http://www.ibm.com/developerworks/java/library/j-jtp07018.html>
explain about generics wildcards.
Joshua Bloch's seminal /Effective Java/ has an entire chapter on generics,
available for free at
<http://java.sun.com/docs/books/effective/generics.pdf>
that explains a lot.
The Sun generics tutorial,
<http://java.sun.com/docs/books/tutorial/extra/generics/index.html>
which of course you've already read or you wouldn't be embarking on this
adventure, has a chapter on wildcards,
<http://java.sun.com/docs/books/tutorial/extra/generics/wildcards.html>
Beware, generics and arrays do not play well together. Instead of
'Class<?>[]' I'd consider 'List <Class <?>>'.
Yes, there's an array under the hood in some 'List' implementations, but at
least the API hides the messiness for you.
Anyway, read the referenced links. It's the minimum to get you competent, or
at least start to, with respect to generics.
--
Lew