当前位置:网站首页>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:
边栏推荐
猜你喜欢
随机推荐
【软件测试】2022年最火的十大测试工具,你掌握了几个
MySQL performance schema性能分析实战
【Linux】宝塔面板设置MySQL慢查询日志,未走索引日志
[Autumn Recruitment] [Updating ing] Hand Tear Code Series
2.0966 铝青铜板CuAl10Ni5Fe4铜棒
线程池如何监控,才能帮助开发者快速定位线上错误?
RecyclerView滑动监听
Android面试冲刺:2022全新面试题——剑指Offer(备战金九银十)
Pengcheng Cup 2022 web/misc writeup
解析方法的参数列表(包含参数名称)
HGAME 2022 复盘 writeup
HFCTF 2021 Internal System writeup
【MySQL】mysql因为字符集导致left join出现Using join buffer (Block Nested Loop)
二叉树 | 递归遍历 | leecode刷题笔记
高性能MySQL核心整理强势来袭
PlaidCTF 2022 Amongst Ourselves:Shipmate writeup
十年架构五年生活-08 第一次背锅
mysql中的三大日志
API服务网关
【Maui正式版】创建可跨平台的Maui程序,以及有关依赖注入、MVVM双向绑定的实现和演示