在 JVM 中加载类时,类的不同部分按什么顺序初始化? [英] In what order are the different parts of a class initialized when a class is loaded in the JVM?

查看:37
本文介绍了在 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 中加载类时,类的不同部分按什么顺序初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆