Gets the information about the function where the method is obtained
1. Get the current function name: Thread.CurrentThread (). Getstacktrace () [1].getmethodname ();
2. Get the current class name: Thread.CurrentThread (). Getstacktrace () [1].getclassname ();
3. Get the file name of the current class: Thread.CurrentThread (). Getstacktrace () [1].getfilename ();
Gets information about the function where the method was called
1. Get the current function name: Thread.CurrentThread (). Getstacktrace () [2].getmethodname ();
2. Get the current class name: Thread.CurrentThread (). Getstacktrace () [2].getclassname ();
3. Get the file name of the current class: Thread.CurrentThread (). Getstacktrace () [2].getfilename ();
Demo:
This is the Get method
1 Public classNameproxy {2 3 Public Static voidNowmethod () {4String clazz = Thread.CurrentThread (). Getstacktrace () [1].getclassname ();5String method = Thread.CurrentThread (). Getstacktrace () [1]6 . Getmethodname ();7System.out.println ("Class name:" + clazz + "Method name" +method);8 }9 Ten Public Static voidParentmethod () { OneString clazz = Thread.CurrentThread (). Getstacktrace () [2].getclassname (); AString method = Thread.CurrentThread (). Getstacktrace () [2] - . Getmethodname (); -System.out.println ("Class name:" + clazz + "Method name" +method); the } - -}
Test:
1 Public class MethodName {23 @Test4public void Showmethodname () {5 logproxyname.nowmethod (); 6 Logproxyname.parentmethod (); 7 }89 }
Show Results:
1 class name:com. XXX.name.NameProxy Method name Nowmethod2class name:com. XXX.name.MethodName Method name Showmethodname
JAVA gets the class name, the name of the function