/**
* 根据方法参数下标索引,获取该方法指定下标参数的名字
* @param method 方法
* @param paramIndex 参数下标
* @return 参数名
*/
public static String getMethodParamNameByParamIndex(Method method, int paramIndex) {
try {
Method getNameMethod = Parameter.class.getMethod("getName");
Method getParametersMethod = Method.class.getMethod("getParameters");
Object[] params = (Object[]) getParametersMethod.invoke(method);
return (String) getNameMethod.invoke(params[paramIndex]);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
二、根据方法参数下标索引,获取该方法指定下标参数的名字
猜你喜欢
转载自blog.csdn.net/panchang199266/article/details/103252890
今日推荐
周排行