Java 静态初始值设定项和反射 [英] Java static initializers and reflection

查看:49
本文介绍了Java 静态初始值设定项和反射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 java 反射 我注意到所有类在以反射为目标.有什么办法可以强制这些静态构造函数返回或根本不运行它们吗?

Using java reflection I noticed that all classes run their static constructors when targeted by reflection. Is there any way that I can force these static constructors to return or not run them at all?

推荐答案

没有.一旦类加载器加载并初始化类,就会调用静态初始化器.

No. The static initializer is invoked as soon as the class is loaded by the classloader and initialized.

这篇关于Java 静态初始值设定项和反射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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