Article Directory
Class loading timing (five kinds)
The virtual machine will trigger the following five cases the class is first loaded
- Encountered
new
,getstatic
,setstatic
,invokestatic
bytecode - Java.lang.reflect package using a method based on the reflecting call
- When loading a class, find its parent class has not been loaded, to load the parent class
- When the virtual machine starts, you need to specify (with a master class
main()
class method), the virtual machine to load such - JDK 1.7 dynamic language support,
java.lang.invoke.MethodHandle
examples of final analytical result is thatREF_getStatic
,REF_setStatic
,REF_invokeStatic
when the method handle, will load the corresponding class
Class initialization sequence
- Parent class
<clinit>
code in the block - Subclass
<clinit>
block code - Parent class
<init>
code in the block - Subclass
<init>
block code
clinit block comprising a block of static variables static
init block comprising a member variable with builder