您的位置:首页 > 其它

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

2017-03-02 15:23 267 查看
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+" ");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐