2

I am trying to come up with a design for a method that takes another method as a parameter and retrieves the parameter values of the method passed. How can this be done? I've tried using java.lang.reflect.* but can't seem to find an API that supports this.

TheWolf
  • 1,675
  • 4
  • 22
  • 34
  • See also https://stackoverflow.com/questions/4943612/java-how-to-get-arguments-passed-to-method-that-called-this-method – Vadzim Jun 13 '19 at 17:48
  • and this is my answer https://stackoverflow.com/a/73263342/5050750 – Amir Aug 06 '22 at 21:32

2 Answers2

5

You can't really get the values passed as parameters like this.

You can make your own Proxy and from there capture parameters before calling the right method. Or with aspect you could get the parameters value directly when the method is called.

Colin Hebert
  • 91,525
  • 15
  • 160
  • 151
-1

Method.getParameterTypes

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/reflect/Method.html#getParameterTypes%28%29

pauljwilliams
  • 19,079
  • 3
  • 51
  • 79