Java class is initialized under what circumstances?

 

Examples of class 1. Create (new way). Access static variables of a class or interface, or assignment of the static variables, static method call class

2. reflection when the reflection method is called classes.

3. When initializing a class, if it is found not to initialize the parent class, you need to first trigger initialization of the parent class.

4. When a virtual machine starts, the user needs to specify a main class to be loaded (that contains the main class method ()), the virtual machine to initialize this master class.

5. When a dynamic language support JDK 1.7, if a final example of the analysis result java.lang.invoke.MethodHandle REF_getStatic, REF_putStatic, REF_invokeStatic the method handle, and this method handle class corresponding not been initialized, need first triggers its initialization.

 

Loaded Java class is dynamic, and it will not be a one-time class will all fully loaded before running, but to ensure the base class running (such as the base class) fully loaded into the jvm, the other class, need when it is loaded. This of course, is to save memory overhead.

 

Guess you like

Origin www.cnblogs.com/linliquan/p/11257716.html