当前位置:网站首页>解析方法的参数列表(包含参数名称)
解析方法的参数列表(包含参数名称)
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("===============================");
}
}
}
}
测试结果:

边栏推荐
- 68: Chapter 6: Develop article services: 1: Content sorting; article table introduction; creating [article] article services;
- 2021 IDEA creates web projects
- 音乐播放器(未完成版本)
- DC-8靶场下载及渗透实战详细过程(DC靶场系列)
- 合并k个已排序的链表
- 二叉树 | 翻转二叉树 | leecode刷题笔记
- QT笔记——用VS + qt 生成dll 和 调用生成的dll
- 3598. 二叉树遍历(华中科技大学考研机试题)
- 留言有奖|OpenBMB x 清华大学NLP:大模型公开课更新完结!
- gcc492 compile `.rodata‘ can not be used when making a PIE object; recompile with -fPIE
猜你喜欢
随机推荐
MySQL学习笔记(2)——简单操作
mmpose关键点(一):评价指标(PCK,OKS,mAP)
实例054:位取反、位移动
RK3399 platform development series explanation (kernel-driven peripherals) 6.35, IAM20680 gyroscope introduction
文件IO-缓冲区
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
ArcGIS应用基础知识
Merge k sorted linked lists
Spark基础【RDD转换算子】
CIKM2022 | 基于双向Transformers对比学习的序列推荐
Shell 编程--Sed
geemap的详细安装步骤及环境配置
This visual tool artifact is more intuitive and easy to use!love so much
MySQL:MySQL的集群——主从复制的原理和配置
HanLP词性表
LeetCode每日两题01:反转字符串 (均1200道)方法:双指针
Nodes in the linked list are flipped in groups of k
68: Chapter 6: Develop article services: 1: Content sorting; article table introduction; creating [article] article services;
Extended Chinese Remainder Theorem
分享一个后台管理系统可拖拽式组件的设计思路








