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

边栏推荐
猜你喜欢
随机推荐
虚拟地址空间
交换机和生成树知识点
geemap的详细安装步骤及环境配置
过滤器
CIKM2022 | Sequence Recommendation Based on Bidirectional Transformers Contrastive Learning
ITK 读取一个目录中的一个序列,然后改变头信息,将多张dcm图像写成一个dcm文件。
fme csmapreprojector转换器使用高程异常模型进行高程基准转换
Lambda
如何成为一名正义黑客?你应该学习什么?
音乐播放器(未完成版本)
2022年8月10日:使用 ASP.NET Core 为初学者构建 Web 应用程序--使用 ASP.NET Core 创建 Web UI(没看懂需要再看一遍)
B站数据分析岗实习生面试记录
罗克韦尔AB PLC RSLogix5000中计数器指令使用方法介绍
12 Recurrent Neural Network RNN2 of Deep Learning
ASCII、Unicode和UTF-8
What would happen if disconnecting during the process of TCP connection?
JS use regular expressions in g model and non g difference
68:第六章:开发文章服务:1:内容梳理;article表介绍;创建【article】文章服务;
Power system power flow calculation (Newton-Raphson method, Gauss-Seidel method, fast decoupling method) (Matlab code implementation)
RecyclerView滑动监听








