jeudi 20 juin 2019

Method to reference current method

Is there a way to pass the current method as a parameter using Reflection? In other words, is there something like the this keyword, but for methods?

For example:

class ReflectionUtils {
  void printMethod(Method method){
    System.out.print(method.getName());
  }
}

// then...

class callerClass {
  void callerMethod(){
    printMethod(/* "this" but for methods */)
  }
}

// would print: "callerMethod"

I want to pass callerMethod from itself to the printMethod method. Is there any way to do this, without parsing the stack trace?





Aucun commentaire:

Enregistrer un commentaire