Getting a list of all the bootstrap classes on the JVM?

送分小仙女□ 提交于 2019-12-23 19:43:35

问题


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?


回答1:


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.

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():

Returns the parent class loader for delegation. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class loader's parent is the bootstrap class loader.



来源:https://stackoverflow.com/questions/22556929/getting-a-list-of-all-the-bootstrap-classes-on-the-jvm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!