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

边栏推荐
猜你喜欢

实例052:按位或

OneNote 教程,如何在 OneNote 中整理笔记本?

Why general company will say "go back messages such as" after the end of the interview, rather than just tell the interviewer the result?

谁是边缘计算服务的采购者?是这六个关键角色

DC-7靶场下载及渗透实战详细过程(DC靶场系列)

威纶通触摸屏如何在报警的同时,显示出异常数据的当前值?

BM13判断一个链表是否为回文结构

亲测有效|处理风控数据特征缺失的一种方法

阿里云新增三大高性能计算解决方案,助力生命科学行业快速发展

MySQL: MySQL Cluster - Principle and Configuration of Master-Slave Replication
随机推荐
边缘与云计算:哪种解决方案更适合您的连接设备?
MySQL之JDBC编程增删改查
H3C S5130 IRF做堆叠
QT笔记——QT工具uic,rcc,moc,qmake的使用和介绍
BM7 list entry in central
Spark基础【RDD转换算子】
3598. 二叉树遍历(华中科技大学考研机试题)
新一代网络安全防护体系的五个关键特征
瑞幸咖啡第二季营收33亿:门店达7195家 更换CFO
virtual address space
Distribution Network Expansion Planning: Consider Decisions Using Probabilistic Energy Production and Consumption Profiles (Matlab Code Implementation)
Shell 编程--Sed
【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示
2021 IDEA creates web projects
阿里云张新涛:支持沉浸式体验应用快速落地,阿里云云XR平台发布
高学历毕业生,该学单片机还是plc?
ITK 读取一个目录中的一个序列,然后改变头信息,将多张dcm图像写成一个dcm文件。
fme csmapreprojector转换器使用高程异常模型进行高程基准转换
Detailed installation steps and environment configuration of geemap
华为HCIE云计算之Fusion Access桌面云