反射之------获得运行时类的方法(非指定)

package com.heima.userJSTL;

import java.lang.reflect.Method;

public class PersomTestMethod {
    public static void main(String[] args) {
        Class<Person> aClass = Person.class;
        Method[] methods = aClass.getMethods();//获取运行时类及其所有父类的所有被public修饰的方法
        for (Method method : methods) {
            System.out.println(method);
        }
        System.out.println("===================");
        Method[] declaredMethods = aClass.getDeclaredMethods();//getDeclaredMethods();获取当前运行时类的所有方法(不包括父类的方法)
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }


    }
}

 

posted @ 2020-10-09 10:38  Joker-0927  阅读(79)  评论(0编辑  收藏  举报
// 侧边栏目录