Does anyone knows what is the different between:
Class clazz = getClass().getClassLoader().loadClass(className);
AND
Class clazz = Class.forName(className);
As i tried both, it gave me same result.
Does anyone knows what is the different between:
Class clazz = getClass().getClassLoader().loadClass(className);
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 :