加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 谁调用类初始化器方法和什么时候?

发布时间:2020-12-14 05:57:57 所属栏目:Java 来源:网络整理
导读:我知道新的,dup,invocation专用和astere字节码模式将调用实例初始化方法 init当有人从 Java语言的角度来实例化一个 Java类时,但是我从来不知道谁调用了特殊的 clinit方法,何时发生这种情况? 我的猜测是 clinit在 init之前调用方法.任何身体能给我一些信息来
我知道新的,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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读