package Fanshe;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
//需求:通过反射实现操作
//Student s=new Student()
//s.method1();
//s.method2("林青霞");
//String ss=s.method2("林青霞",20);
public class Fanshedeom5 {
    public static void main(String[] args) throws Exception {
        Class<?> clss = Class.forName("Fanshe.Student");
        //获取clss对象中的方法,遍历
        Method[] declaredMethods = clss.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
              System.out.println(declaredMethod);
        }
        //获取无参构造
        Constructor<?> stu = clss.getConstructor();
        //创建对象
        Object obj = stu.newInstance();
        //获取方法
        Method m1 = clss.getDeclaredMethod("method1");
        Method m2 = clss.getDeclaredMethod("method2", String.class);
        Method m3 = clss.getDeclaredMethod("method3", String.class,int.class);
        //调用
        m1.invoke(obj);
        m2.invoke(obj,"林青霞");
        m3.setAccessible(true);
        Object ss = m3.invoke(obj, "林青霞", 20);
        System.out.println(ss);
    }
}