S
Steve Sobol
Using reflection...
Class c=Class.forName(classname,false,new URLClassLoader(urlList));
// Get a declared zero-arg constructor
try {
newPlugin = c.getDeclaredConstructor(null).newInstance(null);
} catch(NoSuchMethodException e) {
throw new PluginException(c.getCanonicalName() +
" has no declared zero-argument constructor");
} catch(InvocationTargetException e) {
throw new PluginException("Could not call constructor for " +
c.getCanonicalName());
}
newPlugin is an instance of Class B, which extends class A.
When I call newInstance, class A's constructor is called first, then class
B's constructor, even though Class B doesn't have a call to super().
If I remove Class B's constructor, class A's instructor is still called. I'd
have expected getDeclaredConstructor to throw an exception or return null if
there was no actual constructor declared in B...
Is this the correct behavior?
Class c=Class.forName(classname,false,new URLClassLoader(urlList));
// Get a declared zero-arg constructor
try {
newPlugin = c.getDeclaredConstructor(null).newInstance(null);
} catch(NoSuchMethodException e) {
throw new PluginException(c.getCanonicalName() +
" has no declared zero-argument constructor");
} catch(InvocationTargetException e) {
throw new PluginException("Could not call constructor for " +
c.getCanonicalName());
}
newPlugin is an instance of Class B, which extends class A.
When I call newInstance, class A's constructor is called first, then class
B's constructor, even though Class B doesn't have a call to super().
If I remove Class B's constructor, class A's instructor is still called. I'd
have expected getDeclaredConstructor to throw an exception or return null if
there was no actual constructor declared in B...
Is this the correct behavior?