EVALUATION
Generally speaking reflective loading of a class by name should be accomplished by using this static method in java.lang.Class:
public static Class<?> forName(String name, boolean initialize, ClassLoader loader)
throws ClassNotFoundException
The ClassLoader.loadClass() method is more typically used for class loader delegation. Invocation of Class.forName() may eventually invoke ClassLoader.loadClass() after handling VM name resolution. In particular, for array classes, this would involve loading the array's component type.
Thus, we highly recommend replacement of this code:
myClassLoader.loadClass(className);
With this code:
Class.forName(className,false,myClassLoader);
An appropriate usage note describing the above recommended practice should be added to the ClassLoader javadoc.
|