当前位置:网站首页>解析方法的参数列表(包含参数名称)
解析方法的参数列表(包含参数名称)
2022-08-10 22:30:00 【技术日志】
话不多说,直接上Demo:
public class User {
public static void main(String[] args) throws NoSuchMethodException {
getMethodParams(User.class,"main",null);
}
/**
* 解析方法参数列表:
* @param clazz: 全限定类名
* @param methodName: 方法名
* @param agrCount: n个参数的方法; 为空,则排除此条件;
*/
public static void getMethodParams(Class clazz, String methodName, Integer agrCount) {
//获取指定方法:
Method method = Arrays.stream(clazz.getMethods())
.filter((x) -> {
return methodName.equals(x.getName()) && (Objects.isNull(agrCount) || agrCount.equals(x.getParameterCount()));
})
.findFirst()
.orElse(null);
//获取参数信息:
if (Objects.nonNull(method)) {
for (Parameter parameter : method.getParameters()) {
System.out.println("参数类型: " + parameter.getType());
System.out.println("参数名称: " + parameter.getName());
System.out.println("===============================");
}
}
}
}
测试结果:
边栏推荐
猜你喜欢
随机推荐
合并k个已排序的链表
留言有奖|OpenBMB x 清华大学NLP:大模型公开课更新完结!
JS中使用正则表达式g模式和非g模式的区别
CIKM2022 | 基于双向Transformers对比学习的序列推荐
2022年8月的10篇论文推荐
BM7 list entry in central
This visual tool artifact is more intuitive and easy to use!love so much
A shell script the for loop statements, while statement
阿里云贾朝辉:云XR平台支持彼真科技呈现国风科幻虚拟演唱会
OneNote 教程,如何在 OneNote 中整理笔记本?
EL表达式
JS学习 2022080
68: Chapter 6: Develop article services: 1: Content sorting; article table introduction; creating [article] article services;
【软件测试】2022年最火的十大测试工具,你掌握了几个
解码2022中国网安强星丨正向建、反向查,华为构建数字化时代的网络安全防线
leetcode:357. 统计各位数字都不同的数字个数
RK3399 platform development series explanation (kernel-driven peripherals) 6.35, IAM20680 gyroscope introduction
shell脚本
链表相加(二)
What is Jmeter? What are the principle steps used by Jmeter?