当前位置:网站首页>解析方法的参数列表(包含参数名称)
解析方法的参数列表(包含参数名称)
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("===============================");
}
}
}
}
测试结果:
边栏推荐
猜你喜欢
高数_复习_第5章:多元函数微分学
ArcGIS应用基础知识
亲测有效|处理风控数据特征缺失的一种方法
Qualcomm Platform Development Series Explanation (Application) Introduction to QCMAP Application Framework
RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
BM13 determines whether a linked list is a palindrome
实例055:按位取反
H3C S5130 IRF做堆叠
【640. Solving Equations】
Distribution Network Expansion Planning: Consider Decisions Using Probabilistic Energy Production and Consumption Profiles (Matlab Code Implementation)
随机推荐
二叉树 | 翻转二叉树 | leecode刷题笔记
特别的三杯鸡
Translating scientific and technological papers, how to translate from Russian to Chinese
Introduction to the use of counter instructions in Rockwell AB PLC RSLogix5000
实例050:随机数
Fatal error: cstring: No such file or directory
2021IDEA创建web工程
“数据引擎”开启前装规模量产新赛道,「智协慧同」崭露头角
Research on multi-element N-k fault model of power system based on AC power flow (implemented by Matlab code) [Power System Fault]
RK3399 platform development series explanation (kernel-driven peripherals) 6.35, IAM20680 gyroscope introduction
QT笔记——用VS + qt 生成dll 和 调用生成的dll
带着昇腾去旅行:一日看尽金陵城里的AI胜景
二叉树 | 对称二叉树、相同的树、子树相同 | leecode刷题笔记
美味的佳肴
Redis
RK3399平台开发系列讲解(内核驱动外设篇)6.35、IAM20680陀螺仪介绍
Lambda
3598. 二叉树遍历(华中科技大学考研机试题)
新一代网络安全防护体系的五个关键特征
高通平台开发系列讲解(应用篇)QCMAP应用框架介绍