如何获取方法的参数类型和参数名
示例,要获取的方法
获取参数类型和名称
@Test
public void testGetParamsName() throws Exception {
LocalVariableTableParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
Method[] declaredFields = QrUtil.class.getDeclaredMethods();
for (Method method : declaredFields) {
String[] parameterNames = parameterNameDiscoverer.getParameterNames(method);
Class<?>[] parameterTypes = method.getParameterTypes();
System.out.println("方法名:" + method.getName() + ",参数类型:" + Arrays.toString(parameterTypes) + ",参数名:" + Arrays.toString(parameterNames));
}
}
执行测试用例