0

Know the name of currently executing method in Java

This method is used to get the name of method currently executing.

protected String getCurrentlyExecutingMethodName() {
  Throwable t = new Throwable(); 
  StackTraceElement[] elements = t.getStackTrace(); 
  if (elements.length <= 0) return "[No Stack Information Available]";
  // elements[0] is this method
  if (elements.length < 2) return null;
  return elements[1].getMethodName();
}

|

0 Comments

Copyright © 2009 So That I Can Remember All rights reserved. Theme by Laptop Geek. | Bloggerized by FalconHive.