如何使用Java反射获取参数名称 [英] How to get parameter names with Java reflection

查看:478
本文介绍了如何使用Java反射获取参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Java反射获取方法签名?

How do I get method signatures with Java reflection?

我实际上需要参数NAMES而不是方法的类型.

推荐答案

要获取C类的方法i,请调用C.class.getMethods()[i].toString().

To get the method i of a class C you call C.class.getMethods()[i].toString().

编辑:使用反射API不可能获取参数.

Obtaining parameter names is not possible using the reflection API.

但是如果您使用调试信息编译了类,则可以从字节码中提取信息. Spring使用 ASM字节码工程库来做到这一点.

But wen you compiled your class with debug information, it is possible to extract the information from bytecode. Spring does it using the ASM bytecode engineering library.

有关更多信息,请参见此答案.

See this answer for further information.

这篇关于如何使用Java反射获取参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆