[英]java initialization order with static members
I am not sure whether I have a correct model of Java initialization mechanism in my head. 我不确定我的脑中是否有正确的Java初始化机制模型。 Each class follows the following:
每个类都遵循以下内容:
Initialize follows the following: Initialize遵循以下内容:
Is that precise/correct? 这是准确/正确的吗?
According to the Java language specification , your assumptions are more or less correct. 根据Java语言规范 ,您的假设或多或少是正确的。 The exceptions are that:
例外是:
Code execute as below - 代码执行如下 -
Static init blocks run once, when the class is first loaded. 首次加载类时,静态初始化块运行一次。
Static Variable 静态变量
All Super Constructor. 所有超级构造者。
Instance init blocks run after the constructor's call to super(). 实例初始化块在构造函数调用super()之后运行。
instance variable. 实例变量。
(Init blocks execute in the order they appear.) (Init块按它们出现的顺序执行。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.