问题描述
对于ClassLoader,有一个名为 findBootstrapClass
的方法,该方法在引导时返回Class。
There is a method called findBootstrapClass
for a ClassLoader that returns a Class if it is bootstrapped. Is there a way to find classes has been loaded?
推荐答案
您可以尝试通过以下方法首先获取引导类加载器:调用
You could try to first get the bootstrap class loader by e.g. calling
ClassLoader bootstrapLoader = ClassLoader.getSystemClassLoader().getParent();
然后按如下说明获取该类加载器的类:
and then get the classes of this class loader as explained here: How can I list all classes loaded in a specific class loader.
但是请注意,获取引导类加载器并不可靠,因为它可能不明确存在。因此 ClassLoader.getSystemClassLoader()。getParent()
可能返回null,如:
But note, that getting the bootstrap class loader is not reliable, because it may not explicitly exist. So ClassLoader.getSystemClassLoader().getParent()
may return null, as explained in the Javadoc of ClassLoader#getParent():
这篇关于获取JVM上所有引导类的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!