Get the current class class name and the calling method name in the JAVA method

Get the current class class name

when called in a non-static method

able to pass

this.getClass().getName();

method to get the class name of the current instance

when called in a static method

The static method cannot execute the above method because it is separated from the class instance.

Thread.currentThread().getStackTrace()[1].getClassName();

method to get the current class name

Get the current method name

able to pass

Thread.currentThread().getStackTrace()[1].getMethodName();

method to get the name of the currently called method

**Note: The **getStackTrace() method will return an array of StackTraceElement objects of the call stack, the first element of which is the Thread.getStackTrace() method itself, so the second element in the array is the real calling method, and you can use this method. Analogy to get the method called by the upper layer

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325449677&siteId=291194637