Hello, I'm working on a specific classloader for my application, but I'm having trouble getting the Generics to work the way I would like them too. I have the following:
public interface Loader<E extends GEObject>{
// methods
}
public class GEClassLoader<E extends GEObject> extends URLClassLoader implements Loader<E>{
// methods
}
GEObject is the base class for all objects in my application. The loader is supposed to search the supplied directory for the classes that extend E (where E is an interface/abstract class that inherits GEObject). When I load a class, I want to check its class against that of E.
So, I have to following, but it doesn't work due to the above reasons: It's complaining about the if(o instanceof E) line...
try{
Class c = loadClass(pkg+name, true);
try{
Object o = c.newInstance();
E e = null;
if(o instanceof E){
e = (E)o;
cis.add((E)ci); // list of classes loaded
}
}catch(Exception e){
// Handle exception
}
}catch(ClassNotFoundException cnfe){
System.out.println("Couldn't find Class "+pkg+name);
}
Note, If I could use 1.6 for this project, I would, but I'm stuck with 1.5... 1.6 would make this much easier....