문제

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top