jeudi 15 juin 2017

Obtain java.lang.reflect.Executable of current or calling method?

How can one obtain objects of the following types from specific instances of their represented language feature in the code:

  • java.lang.reflect.Executable
  • java.lang.reflect.Parameter

Ideally the providing method would be a caller of the obtaining method or the obtaining method itself.

Note that I have found two kinds of answers on SO:

  • how to get a Parameter from a given Executable object (trivial!)
  • how to get the name (not signature!) of a method from the call stack

Neither helps to obtain the Parameter to a particular method whose name is not unique.

Consider in particular how this answer and this one to similar questions gloss over the selection of the desired method.

Now, there exists Class.getMethod(String, Class<?>... types) but it does not seem that one could generate the "types" parameter automatically from an existing method definition?





Aucun commentaire:

Enregistrer un commentaire