我知道新的,dup,invocation专用和astere字节码模式将调用实例初始化方法< init>当有人从
Java语言的角度来实例化一个
Java类时,但是我从来不知道谁调用了特殊的< clinit>方法,何时发生这种情况?
我的猜测是< clinit>在< init>之前调用方法.任何身体能给我一些信息来证明吗?这是否记录在JVM规范或Java语言规范中?
JVM规格
§2.9. Special Methods:
A class or interface has at most one class or interface initialization method and is initialized (§5.5) by invoking that method. The initialization method of a class or interface has the special name <clinit>
,takes no arguments,and is void (§4.3.3).
The name <clinit>
is supplied by a compiler. Because the name is not a valid identifier,it cannot be used directly in a program written in the Java programming language. Class and interface initialization methods are invoked implicitly by the Java Virtual Machine; they are never invoked directly from any Java Virtual Machine instruction,but are invoked only indirectly as part of the class initialization process.
有关类初始化过程的更多详细信息,请参阅Chapter 5.