I need to get the parameter names of a method at runtime. Is there any way to achieve this?
I tried using LocalVariableTableParameterNameDiscoverer which is a Spring class. But it works only for classes and not the interfaces.
The only way to obtain the parameter names is to compile the source code using -g:vars options. This generates a LocalVariableTable attribute into the class file. This is generally removed for optimization. 
For example: (taken from here)
public class Example {
   public int plus(int a){
     int b = 1;
     return a + b;
   }
 }
This will create a LocalVariableTable as follows
LocalVariableTable:
   Start  Length  Slot  Name     Signature
   0      6       0     this     LExample;
   0      6       1     a        I
   2      4       2     b        I
The LocalVariableTable can be read using any byte code instrumentation libraries like ASM or Javassist. 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With