Who invokes the class initializer method and when?

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

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

3条回答
  •  旧时难觅i
    2021-02-08 05:50

    are the static initialization blocks for the class, and static field initialization and its invoked by JVM.

    Java Spec says, http://java.sun.com/docs/books/jvms/second_edition/html/Overview.doc.html#12174

    The initialization method of a class or interface is static and takes no arguments. It has the special name . This 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
    

提交回复
热议问题