Java查看当前类执行过程中加载的所有类
版权声明:本文为博主原创文章,转载请注明作者和出处! https://blog.csdn.net/tterminator/article/details/53507987
有时候需要查看在当前类执行的过程中,都载入了哪些类。
一、自定义的需要载入的类
public class Persion implements Serializable{
String name;
int age;
public Persion(String name, int age){
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
三、完整测试代码
public class ClassLoadTest {
public static void main(String[] args) throws Exception {
Persion p = new Persion("zhansan", 20);
Field f=ClassLoader.class.getDeclaredField("classes");
f.setAccessible(true);
Vector classes=(Vector)f.get(ClassLoader.getSystemClassLoader());
System.out.println(classes);
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
四、测试结果
[class test.ClassLoadTest, class test.Persion]
- 1
转载请注明:SuperIT » Java查看当前类执行过程中加载的所有类