Need to know name of method I'm in.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Eric_Deslauriers
Posted On:   Tuesday, July 29, 2003 06:19 PM

I'm familiar with this.getClass().getName(); which returns the class name.



However, I'm unable to figure out how to return the name of the method I'm in as a string.



I was hoping for something like this.getClass.getMethod().getName(); No joy.



Looking through the reflection classes, etc, they all presuppose you know the method name you want to call. I'm coming from the other end.



I want to know the name of the method I'm in.



Help!



Thanks!

Eric

Re: Need to know name of method I'm in.

Posted By:   David_Bates  
Posted On:   Tuesday, July 29, 2003 11:46 PM

There are some dirty ways to work this out. If you're on an early version of Java, you could create an Exception, re-direct its stacktrace to a string and then use Regex. I think since 1.4.1 there has been a StackTrace object, which would be a little tidier.



Out of interest, why would you ever need this?
About | Sitemap | Contact