Does anyone knows what is the different between:
Class clazz = getClass().getClassLoader().loadClass(className)开发者_Go百科;
AND
Class clazz = Class.forName(className);
As i tried both, it gave me same result.
Class.forName(className)
execute the static initializer code blocks in the loaded class.
A call to forName("X") causes the class named X to be initialized.
getClass().getClassLoader().loadClass(className)
doesn't.
Class.forName(className, false, getClass().getClassLoader())
is the same as getClass().getClassLoader().loadClass(className)
.
Resources :
- javadoc -
Class.forName()
- Javadoc -
ClassLoader.loadClass()
- JLS - Initialization of Classes and Interfaces
精彩评论