反射常用方法

public class a {

    public static void main(String[] args) {
        Person person = new Person();
        //getClass():取得当前对象所属的Class对象
        Class<? extends Person> aClass = person.getClass();
        //反射获取类加载器
        ClassLoader classLoader = Person.class.getClassLoader();
        //获取类实现的接口数组
        Class<?>[] interfaces = Person.class.getInterfaces();
        for (Class<?> anInterface : interfaces) {
            System.out.println(anInterface);
        }
//        System.out.println(interfaces);
    }
}

class Person implements Sport {

}

 

posted @ 2022-04-18 11:21  ❉SSs  阅读(23)  评论(0编辑  收藏  举报