dcsimg
How do I find the name of the class that has called a particular method.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kartik_Shah
Posted On:   Friday, January 11, 2002 05:25 AM

Hi,



I need to find the name of the class that has called a particular function.
E.g. If class A call a method as getName() of class B, then how can the method getName() of class B determine the name of the class hat called it, in this case it is class A.



Can someone tell me the method how to do that.



Thanks


Kartik

Re: How do I find the name of the class that has called a particular method.

Posted By:   Christopher_Schultz  
Posted On:   Friday, January 11, 2002 05:48 AM

Before JDK 1.4, you had to get a stack trace as a String and parse it yourself (search JavaWorld for 'check point' -- they've got an article where they implement fine-grained access control for methods based upon their caller).



In JDK 1.4, there's a way to get detailed information about a stack trace so that you don't have to parse it. Take a look at the javadoc for the Throwable class and see what's available.



-chris
About | Sitemap | Contact