having the method
public void foo(){
//..
}
Is there a way to get the methodName (in this case foo) at runtime?
I know how to get the classname via
this.getClass().getName()
or to get all public methods via
Method[] methods = this.getClass().getMethods();
Once I have the method name the parameters would also be important as there could be several methods with same name
I’m not sure why you need to do this, but you can always create a
new Throwable()andgetStackTace(), then queryStackTraceElement.getMethodName().As a bonus, you get the whole stack trace up to the execution point, not just the immediately enclosing method.
Related questions