> Look at the Javadocs: ClassLoader.loadClass(String) returns a Class<?>.
> You can assign it to a variable of that type without warning. This
[quoted text clipped - 5 lines]
> and previous compilers didn't). You should load the class per your last
> example, and put up with the type safety warning that you will get.

Signature
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty
> Yep, returning Class<?> makes perfect sense, but warning me when I cast it
> to Class<LinkHandler> less so - after all I am explicitly casting.
In the particular instance of casting to Class<LinkHandler>, you
probably shouldn't be doing this anyway. If you can refer to the class
lexically from the code, then you should just use a class literal
expression instead of ClassLoader.loadClass to obtain the reference.
However, you might wish to cast the reference to something else, for
example, Class<? extends LinkHandler>, and the problem would still
apply.
> I'd really like to get rid of the compiler warnings when
> I'm doing things right - otherwise i'll either start ignoring them, or turn
> them off - neither of which is likely to improve my code's type safety! :-)
It's unfortunately not really possible to develop with generics and
warnings for unchecked casts enabled, without just ignoring certain
compiler warnings.

Signature
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Josef Garvi - 30 Apr 2005 07:59 GMT
>>Yep, returning Class<?> makes perfect sense, but warning me when I cast it
>>to Class<LinkHandler> less so - after all I am explicitly casting.
[quoted text clipped - 6 lines]
> example, Class<? extends LinkHandler>, and the problem would still
> apply.
Yes, Class<? extends LinkHandler> is what I should cast it to.
It's a plugin system, so I can't no the precise class at compile time.
>>I'd really like to get rid of the compiler warnings when
>>I'm doing things right - otherwise i'll either start ignoring them, or turn
[quoted text clipped - 3 lines]
> warnings for unchecked casts enabled, without just ignoring certain
> compiler warnings.
Ok.
I've returned to just using Class<?> and using a cast at newInstance().
That way, at least I don't need to get bugged by the warning.

Signature
Josef Garvi
"Reversing desertification through drought tolerant trees"
http://www.eden-foundation.org/
new income - better environment - more food - less poverty