I am trying to do something similar to the following:
I have default constructor that takes no arguments, but I still get an InstantiationException on the line (InterfaceType)c.newInstance();
Class c = null;
try {
c = Class.forName("com.path.to.ImplementationType");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
InterfaceType interfaceType = null;
try {
interfaceType = (InterfaceType)c.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Aucun commentaire:
Enregistrer un commentaire