62,614
社区成员
发帖
与我相关
我的任务
分享
import java.lang.reflect.Field;
import java.util.Vector;
public class Test_ {
public static void main(String[] args) throws SecurityException,
NoSuchFieldException, IllegalArgumentException,
IllegalAccessException, ClassNotFoundException {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Class cla = classLoader.getClass();
while (cla != ClassLoader.class)
cla = cla.getSuperclass();
Field field = cla.getDeclaredField("classes");
field.setAccessible(true);
Vector v = (Vector) field.get(classLoader);
for (int i = 0; i < v.size(); i++) {
System.out.println(((Class)v.get(i)).getName());
}
}
}
import java.lang.reflect.Field;
import java.util.Vector;
public class Test_ {
public static void main(String[] args) throws SecurityException,
NoSuchFieldException, IllegalArgumentException,
IllegalAccessException, ClassNotFoundException {
ClassLoader classLoader = Test_.class.getClassLoader();
Class cla = classLoader.getClass();
while (cla != ClassLoader.class)
cla = cla.getSuperclass();
Field field = cla.getDeclaredField("classes");
field.setAccessible(true);
Vector v = (Vector) field.get(classLoader);
for (int i = 0; i < v.size(); i++) {
System.out.println(v.get(i).getClass().getName());
}
}
}