package J20250806.reflection;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo07_MethodTest
 * @description Class获取方法相关操作
 * @create 2025/8/6
 */
public class Demo07_MethodTest {
    public static void main(String[] args) throws NoSuchMethodException {
        Class<Person> personClass = Person.class;
        //获取所有公共方法--包含从父类继承的方法
        Method[] personClassMethods = personClass.getMethods();
        System.out.println(Arrays.toString(personClassMethods));
        //获取所有方法
        Method[] personClassDeclaredMethods = personClass.getDeclaredMethods();
        System.out.println(Arrays.toString(personClassDeclaredMethods));
        //获取单个公共方法
        Method setName = personClass.getMethod("setName", String.class);
        System.out.println(setName);
        //获取单个方法
        Method showName = personClass.getDeclaredMethod("showName", String.class);
        System.out.println(showName);

    }
}
