获取注解,权限修饰符,返回值类型,方法名,形参列表,异常

    public void test5(){
        Class c=Persion.class;
        //getDeclaredMethods():获取运行时类本身声明的所有的方法
        Method[]  m1=c.getDeclaredMethods();
        for (Method method:m1) {
            System.out.println(method);

            //1.获取此类中所有的注解
            Annotation[] annotation=c.getAnnotations();
            for (Annotation annotation1:annotation) {
                System.out.println(annotation1);
            }
            //2.获取权限修饰符
            String str=Modifier.toString(c.getModifiers());
            System.out.println(str);

            //3.获取返回值类型
            Class returnType=method.getReturnType();
            System.out.println(returnType+" ");
            //4.获取方法名
            String methodName=method.getName();
            System.out.println(methodName+" ");

            //5.获取形参列表
            System.out.println("(");
            Class[] params=method.getParameterTypes();
            for (int i=0;i<params.length;i++) {
                System.out.println(params[i].getName()+"args-"+i+" ");
            }
            //6.获取异常
            Class[] exception=method.getExceptionTypes();
            for (int i=0;i<exception.length;i++) {
                System.out.println(exception[i].getName()+"args-"+i+" ");
            }
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值