Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created November 1, 2012 22:06
Show Gist options
  • Save volgar1x/3996976 to your computer and use it in GitHub Desktop.
Save volgar1x/3996976 to your computer and use it in GitHub Desktop.
get all loaded classes from a ClassLoader
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