Mega Code Archive

 
Categories / Java / Reflection
 

Get the current method name With JDK1 5

public class Main {   public static void main(String args[]) {     trace(Thread.currentThread().getStackTrace());   }   public static void trace(StackTraceElement e[]) {     boolean doNext = false;     for (StackTraceElement s : e) {       if (doNext) {         System.out.println(s.getMethodName());         return;       }       doNext = s.getMethodName().equals("getStackTrace");     }   } }