You can dynamically load a class using this java.lang.Class method:
public static Class<?> forName(String name, boolean initialize, ClassLoader loader)
According to JavaDoc , the second parameter is used to control the initialization time of the class (execution of static initialization code). If true , the class is initialized after loading and during the execution of this method; if false , initialization is delayed until the first use of the class.
Now I understand all this, but the documents do not say how to decide which strategy to use. Is it always better to do initialization immediately? Is it always better to delay it for the first use? Does it depend on the circumstances?
java classloader
Simon kissane
source share