posted 15 years ago
Possible, but not 100% reliable. Thread.currentThread().getStackTrace[0] is a java.lang.StackTraceElement object which can tell you the class name, method name, source file, and source line for the currently executing method. For non-overloaded methods, that's enough. For overloaded methods, you could use the source file/line number and something like BCEL to examine the line number tables in the class file to figure out which overload is being invoked.
Of course, sometimes source file/line number isn't available. And some methods may be "optimized away" so that they don't show a stack frame at all!
So, the bottom line is you can do it, it's not terribly hard, but it won't always work.