How to get parameter names with Java reflection
Solution 1
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.
Solution 2
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/reflect/Method.html#toString()
use the toString()
method of java.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:
Method toString = class.forName("java.lang.String").getDeclaredMethod("toString");
System.out.println(toString);
javatar
Programmer, Researcher&Instructor, Engineering Manager/Director, Clean code & Open Source lover https://www.linkedin.com/in/bariscangungor/ https://www.originium.com/
Updated on June 21, 2022Comments
-
javatar about 2 years
How do I get method signatures with Java reflection?
EDIT: I actually need the parameter NAMES not the types of a method.
-
bmoran over 12 years