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

边栏推荐
- ASCII、Unicode和UTF-8
- PyQt5 窗口自适应大小
- 链表相加(二)
- RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
- Leave a message with a prize | OpenBMB x Tsinghua University NLP: The update of the large model open class is complete!
- 3598. Binary tree traversal (Huazhong University of Science and Technology exam questions)
- CFdiv2-Common Number-(奇偶数二分+规律)
- ITK 读取一个目录中的一个序列,然后改变头信息,将多张dcm图像写成一个dcm文件。
- BM13 determines whether a linked list is a palindrome
- 金山云CEO王育林离职:正值冲刺港股之际 雷军曾送金砖
猜你喜欢
随机推荐
Why general company will say "go back messages such as" after the end of the interview, rather than just tell the interviewer the result?
虚拟地址空间
亲测有效|处理风控数据特征缺失的一种方法
电力系统潮流计算(牛顿-拉夫逊法、高斯-赛德尔法、快速解耦法)(Matlab代码实现)
谁是边缘计算服务的采购者?是这六个关键角色
file IO-buffer
RecyclerView设置缓存大小
罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
美味石井饭菜
BM7 链表中环的入口结点
How to be a Righteous Hacker?What should you study?
Merge k sorted linked lists
August 10, 2022: Building Web Applications for Beginners with ASP.NET Core -- Creating Web UIs with ASP.NET Core
CIKM2022 | Sequence Recommendation Based on Bidirectional Transformers Contrastive Learning
y93.第六章 微服务、服务网格及Envoy实战 -- Envoy配置(四)
带着昇腾去旅行:一日看尽金陵城里的AI胜景
ArcGIS中的坐标系统和投影变换
leetcode:357. 统计各位数字都不同的数字个数
边缘与云计算:哪种解决方案更适合您的连接设备?
Fatal error: cstring: No such file or directory









