当前位置:网站首页>Parse method's parameter list (including parameter names)
Parse method's parameter list (including parameter names)
2022-08-10 23:29:00 【Technical log】
Don't say much, just go to Demo:
public class User {public static void main(String[] args) throws NoSuchMethodException {getMethodParams(User.class,"main",null);}/*** Parse method parameter list:* @param clazz: fully qualified class name* @param methodName: method name* @param agrCount: method with n parameters; if it is empty, this condition is excluded;*/public static void getMethodParams(Class clazz, String methodName, Integer agrCount) {//Get the specified method:Method method = Arrays.stream(clazz.getMethods()).filter((x) -> {return methodName.equals(x.getName()) && (Objects.isNull(agrCount) || agrCount.equals(x.getParameterCount()));}).findFirst().orElse(null);//Get parameter information:if (Objects.nonNull(method)) {for (Parameter parameter : method.getParameters()) {System.out.println("Parameter type: " + parameter.getType());System.out.println("Parameter name: " + parameter.getName());System.out.println("=================================");}}}}Test results:

边栏推荐
猜你喜欢
随机推荐
实例052:按位或
数组 冒泡排序
矩阵的迹(详解)
CW614N铜棒CuZn39Pb3对应牌号
开源一夏 | 盘点那些 Golang 标星超过 20 K 的优质项目
CSAPP lab
HGAME 2022 Week4 writeup
Ndk 和Cmake报错解决
二叉树 | 翻转二叉树 | leecode刷题笔记
Three major logs in mysql
生态伙伴开发实践 | 智慧检测实验室应用系统快速接入指令集数字底座
(PC+WAP)带手机端pbootcms模板园林景观类网站
ACTF 2022 writeup
MySQL之JDBC编程增删改查
sklearn.datasets.make_circles
Kubernetes 选举机制HA
Btree index and Hash index
HGAME 2022 Week2 writeup
二叉树 | 代码随想录学习笔记
响应式pbootcms模板五金配件类网站








