I need the java java.lang.reflect.Method. And not the name of the method. I have many functions like these where I need the method Object based on the current Method. Currently I am using the pattern to get the Method object. But I am sure there would be some way to get the method object directly and some one could help me with even modulating this code not just having to copy paste some line to every function in my class.
Consider the following code.
public boolean insertNow(List<Insert> insertOperations) {
return sendRemote(this.getClass().getMethod(new Exception().getStackTrace()[0].getMethodName(), List.class), params);
}
So to summarize it I need help with the following 2 things.
- Get Method object from inside method.
- Make it modular so that I don't have to copy paste it to every method in my code.
I know I can change to Exception().getStackTrace()[1]
inside another function which I call from here. But is that safe and is it recommended!?