Skip to main content

generic, isAssignableFrom and Xlint warnings

1 reply [Last post]
kobit
Offline
Joined: 2003-06-13

Hi,

I have some code as follows:
public void
findClassesImplementing(Set classes, Class cls) {

for (Class c : classes) {
if (cls.isAssignableFrom(c)) {
// Do something here
} // end of if (cls.isAssignableFrom(c))
} // end of for ()

}

Code above compiles and works fine however I am getting
compilation Xlint warning:
warning: [unchecked] unchecked call to isAssignableFrom(java.lang.Class<?> ) as a member of the raw type java.lang.Class
[javac] if (cls.isAssignableFrom(c)) {

But to tell you the truth I can realy know how to change my code to make compiler more happy.
The idea of this code is to find all available classes implementing or extending given class.
'classes' Set is built from all available classes found in 'classpath'.

Do you have any suggestion how to use 'isAssignableFrom' method correctly to have code correct "Tiger way"?

Artur Hefczyc

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
brucechapman
Offline
Joined: 2004-03-18

Wrong forum but your problem is due to the fact that Class is now generic. try this
[code]
public void
findClassesImplementing(Set> classes, Class cls) {
for (Class c : classes) {
if (cls.isAssignableFrom(c)) {
// Do something here
} // end of if (cls.isAssignableFrom(c))
} // end of for ()
}
[/code]

you might get away with only adding the type parameters to "cls" which is the reference that generated the warning.