Get the current method name in Java

Description

The following code shows how to get the current method name.

Example


//w w  w  .j  a  va2s .com
public class Main{
    public static void main(String args[]) {
      System.out.println
         (new Exception().getStackTrace()[0].getMethodName());
    }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    Reflection »




Annotation
Array
Class
Constructor
Field
Generics
Interface
Method
Modifier
Package
Proxy