When loading the class, using method forName(), any static initializers in the class are executed.
Can I prevent this ?
try {
Class.forName("MYClass");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MyClass
class MyClass{
static String TEST="MYCLASS";
static SomeClass sm=new SomeClass();
}
I found in doc that there is a overloaded version of Class.forName() i.e.
public static Class<?> forName(String name,
boolean initialize,
ClassLoader loader)
throws ClassNotFoundException
What is initialize parameter ?
If you dont want to execute static initialization try class literal instead of Class.forName