如何使用Java反射获取参数名称
如何使用 Java 反射获取方法签名?
编辑: 我实际上需要参数 NAMES 而不是方法的类型。
How do I get method signatures with Java reflection?
EDIT:
I actually need the parameter NAMES not the types of a method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要获取类 C 的方法 i,请调用
C.class.getMethods()[i].toString()
。编辑:使用反射API无法获取参数名称。
但是当您使用调试信息编译类时,可以从字节码中提取信息。 Spring 使用 ASM 字节码工程库 来完成此操作。
有关更多信息,请参阅此答案。
To get the method i of a class C you call
C.class.getMethods()[i].toString()
.EDIT: Obtaining parameter names is not possible using the reflection API.
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.
http:// docs.oracle.com/javase/1.5.0/docs/api/java/lang/reflect/Method.html#toString()
使用
toString()
方法您正在查找的方法的java.lang.reflect.Method
对象。如果你想知道如何获取该方法对象,只需使用 this 作为引用:
它会打印:
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/reflect/Method.html#toString()
use the
toString()
method ofjava.lang.reflect.Method
object for the method you are looking for.If you want to know how to get that method object just use this as a reference:
and it prints: