Created
November 1, 2012 22:06
-
-
Save volgar1x/3996976 to your computer and use it in GitHub Desktop.
get all loaded classes from a ClassLoader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private List<Class<?>> getClasses(ClassLoader classLoader) throws ReflectiveOperationException { | |
Class<?> clazz = classLoader.getClass(); | |
while (clazz != ClassLoader.class) { | |
clazz = clazz.getSuperclass(); | |
} | |
Field field = clazz.getDeclaredField("classes"); | |
field.setAccessible(true); | |
return new ArrayList<Class<?>>((Collection<Class<?>>) field.get(classLoader)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment