Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

类初始化的时机中关于静态常量的表述有误 #2580

Open
donghuiyong opened this issue Jan 10, 2025 · 0 comments
Open

类初始化的时机中关于静态常量的表述有误 #2580

donghuiyong opened this issue Jan 10, 2025 · 0 comments

Comments

@donghuiyong
Copy link

donghuiyong commented Jan 10, 2025

当 jvm 执行 getstatic 指令时会初始化类。即程序访问类的静态变量(不是静态常量,常量会被加载到运行时常量池)。

来自https://javaguide.cn/java/jvm/class-loading-process.html#%E5%88%9D%E5%A7%8B%E5%8C%96
准确来说是访问编译期常量不会初始化类,访问运行时常量还是会初始化类,见https://blog.csdn.net/qq_34802416/article/details/83548369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant