Home Java Java-get-example Get Calling Method



Get Calling Method
Posted on: October 23, 2008 at 12:00 AM
In this example we will find the name of the method. Description of the method used in the example: getStackTrace: Provides programmatic access to the stack trace information printed by printStackTrace(). It returns array of StackTraceElement objects.

Get Calling Method

     

In this example we will find the name of the method.
Description of the method used in the example:
getStackTrace: Provides programmatic access to the stack trace information printed by printStackTrace(). It returns array of StackTraceElement objects.
getMethodName: It returns String type name of the method containing the execution point represented by this stack trace element.

 

 

public class GetCallingMethod {
  public static void main(String args[]) {
  new GetCallingMethod().call();
  }
  public void call() {
  System.out.println
 (new Exception().getStackTrace()[0].getMethodName());
  }
}

 

Output will be displayed as:

 

Download Source Code

 

Related Tags for Get Calling Method:
cidearrayormformscriptobjectioobjectsstackmethodsedformatprintfindgetiptracevitracstacktracenamereturnintthisidelementforexampleprogramtoramexaminformationdescriptioneilitdesuseceinrminfostamnttrjaceesemmeobjproackxaxampsurneeessatracracekisinfllmplraygetsarccscrssriripthstaccessatictsfininforminformatjepleplprprintstacktracendonogro


More Tutorials from this section

Ask Questions?    Discuss: Get Calling Method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.