当前位置:网站首页>解析方法的参数列表(包含参数名称)
解析方法的参数列表(包含参数名称)
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("===============================");
}
}
}
}
测试结果:
边栏推荐
- IM 即时通讯开发如何设计图片文件的服务端存储架构
- 如何利用fiddler连接手机抓包APP
- Why general company will say "go back messages such as" after the end of the interview, rather than just tell the interviewer the result?
- 解码2022中国网安强星丨正向建、反向查,华为构建数字化时代的网络安全防线
- 今日睡眠质量记录75分
- 企业云存储日常运行维护实践经验分享
- 实例054:位取反、位移动
- JS use regular expressions in g model and non g difference
- How to be a Righteous Hacker?What should you study?
- 高数_复习_第5章:多元函数微分学
猜你喜欢
随机推荐
DC-9靶场下载及渗透实战详细过程(DC靶场系列)
基于交流潮流的电力系统多元件N-k故障模型研究(Matlab代码实现)【电力系统故障】
PyQt5 窗口自适应大小
STL-deque
CIKM2022 | 基于双向Transformers对比学习的序列推荐
MySQL Advanced Commands
JS中使用正则表达式g模式和非g模式的区别
BM7 list entry in central
2022年8月的10篇论文推荐
CFdiv2-Common Number-(奇偶数二分+规律)
gcc492 compile `.rodata‘ can not be used when making a PIE object; recompile with -fPIE
Lambda
【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
谁是边缘计算服务的采购者?是这六个关键角色
3598. Binary tree traversal (Huazhong University of Science and Technology exam questions)
文件IO-缓冲区
虚拟地址空间
艺术与科技的狂欢,阿那亚2022砂之盒沉浸艺术季
《DevOps围炉夜话》- Pilot - CNCF开源DevOps项目DevStream简介 - feat. PMC成员胡涛
链表中的节点每k个一组翻转