How to get parameter names with Java reflection

javatar picture javatar · Jan 31, 2012 · Viewed 15k times · Source

How do I get method signatures with Java reflection?

EDIT: I actually need the parameter NAMES not the types of a method.

Answer

mtsz picture mtsz · Jan 31, 2012

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.