Who invokes the class initializer method and when?

后端 未结 3 709
鱼传尺愫
鱼传尺愫 2021-02-08 05:11

I know that the new, dup, invokespecial and astore bytecode pattern will invoke the instance initializer meth

3条回答
  •  北海茫月
    2021-02-08 06:15

    JVM spec §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 , takes no arguments, and is void (§4.3.3).

    The name 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.

    See Chapter 5 for further details on the class initialization process.

提交回复
热议问题