通过反射获取权限修饰符 返回值类型 方法名
@Test
public void test2() {
Class clazz = Person.class;
Method[] declaredMethods = clazz.getDeclaredMethods();
for (Method m : declaredMethods) {
Annotation[] annos = m.getAnnotations();
for (Annotation a : annos) {
System.out.println(a);
}
System.out.println(Modifier.toString(m.getModifiers()));
System.out.println(m.getReturnType().getName());
System.out.println(m.getName());
Class<?>[] parameterTypes = m.getParameterTypes();
if (!(parameterTypes == null && parameterTypes.length == 0)) {
for (int i = 0; i < parameterTypes.length; i++) {
if (i == parameterTypes.length - 1) {
System.out.println(parameterTypes[i].getName() + "" + i);
break;
}
System.out.println(parameterTypes[i].getName() + "" + i + ",");
}
}
System.out.println("()");
Class<?>[] exceptionTypes = m.getExceptionTypes();
if (!(exceptionTypes == null && exceptionTypes.length == 0)) {
System.out.println("throws");
for (int i = 0; i < exceptionTypes.length; i++) {
if (i == exceptionTypes.length - 1) {
System.out.println(exceptionTypes[i].getName());
break;
}
System.out.println(exceptionTypes[i].getName() + ",");
}
}
}
}