Originally posted by David O'Meara:
If you absolutely need a solution and don't care how ugly it is, throw and catch an exception then parse the stack trace for the Class name...
Nope, you can't, it won't work. Try it. You'll get the name of the class in which the method is implemented, not the name of the (sub)class through which the method was invoked.
I can only reiterate my earlier answer: there is no equivalent. The code snippets I gave may not be what was asked for, but they are as close as you can get. Static calls are bound at compile time. It is impossible to receive run-time information about this because
there is no such run-time information. If B extends A then B.staticMethod() compiles to the very same bytecode as A.staticMethod() (assuming staticMethod() is not overridden in B) - a single invokestatic operation on the method implementation class. Again, try it, create the classes then run the calls through javap -c.
I would not expect the JDK 1.4 stack trace to be any different. More easily accessible, but no different. The VM spec didn't change, or did it?
- Peter
[This message has been edited by Peter den Haan (edited October 29, 2001).]