当前位置:网站首页>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:

边栏推荐
猜你喜欢
随机推荐
Kubernetes 计算CPU 使用率
2.0966 铝青铜板CuAl10Ni5Fe4铜棒
sklearn.datasets.make_circles
互联网中不可缺失的网络优化:“App与Server的交互依赖于网络”
PlaidCTF 2022 Amongst Ourselves:Shipmate writeup
ACTF 2022 writeup
HGAME 2022 Week4 writeup
【软件测试】2022年最火的十大测试工具,你掌握了几个
二叉树 | 翻转二叉树 | leecode刷题笔记
二叉树 | 递归遍历 | leecode刷题笔记
62.【彻底改变你对C语言指针的厌恶(超详细)】
vr工业操作培训模拟系统可以应用到哪些场景中
2022牛客多校(七)K. Great Party博弈方法证明
HPb59-1铅黄铜
mysql中的三大日志
卷积神经网络CNN详细介绍
性能不够,机器来凑;jvm调优实战操作详解
N1BOOK writeup
十年架构五年生活-08 第一次背锅
CW614N铜棒CuZn39Pb3对应牌号









