In what order are the different parts of a class initialized when a class is loaded in the JVM?(在 JVM 中加载类时,类的不同部分按什么顺序初始化?)
问题描述
想象一个 Java 类,它具有您可以在一个类中找到的大多数特性.例如:它继承自另一个类,实现了几个接口,包括一些静态最终"常量,一些最终常量,一些静态变量,实例变量,一个静态块,一个未命名的代码块(只是 {} 中的代码),构造函数、方法等.
Imagine a Java class which has most features that you can find in a class. For example: it inherits from another class, implements a couple of interfaces, includes some 'static final' constants, some final constants, some static variables, instance variables, a static block, an unnamed code block (just code in {}), constructors, methods etc.
当有问题的类第一次加载到 JVM 中时,类的各个部分按什么顺序初始化或加载到 JVM 中?JVM 中用于加载的调用堆栈是什么样的?假设这里只有一个类加载器在工作.
When the class in question is loaded into the JVM for the first time, in what order are the various portions of the class initialized or loaded into the JVM? What does the call stack in the JVM look like for the loading? Assume that only one classloader is at work here.
这要回到 Java 的绝对基础/内部原理,但我还没有找到解释正确顺序的好文章.
This is going back to the absolute basics/internals of Java, but I havent been able to find a good article explaining the correct sequence.
推荐答案
JLS,特别是第 12.4 节?
How about the JLS, specifically section 12.4?
这篇关于在 JVM 中加载类时,类的不同部分按什么顺序初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 JVM 中加载类时,类的不同部分按什么顺序初始化?
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
