I have a class which is implementing an interface with generics.
class MainClass {
interface MyInterface <T extends MyInterface.A> {
static class A {
}
}
}
//I have another class which implements this interface:
class ImplementingClass implements MyInterface<A> {
}
//I am loading MyInterface class from a jar in a different place:
static loadJar(){
String dexPath = new ContextWrapper(context).getCacheDir().getAbsolutePath();
DexClassLoader classLoader = new DexClassLoader(JAR_FILE, dexPath, null, ClassLoader.getSystemClassLoader());
Class c = classLoader.loadClass("ImplementingClass");
MyInterface nvQS = (MyInterface) c.newInstance();
}
I am getting a class cast exception. I am not sure why is that? The class is implementing the interface. I tried it with the generics as well but I still get the exception.
Please let me know in case I am not clear. Thanks.
Including the Exception : java.lang.ClassCastException: ImplementingClass cannot be cast to MainClass$MyInterface
Hey, the interface is build as a java static library in android. The jar and the jar loader will be compiled against separate copies right? Is that a problem? Do you think that is why I might be getting a class cast?