Suppose I have a class called A and in that a method meth,
and if A is instaniated in tow class B and C, is there any way to know the name of the callin class in the method meth of A ? (the calling object should not be passed).
-
How can I know the calling class name ? (2 messages)
- Posted by: Udaya Bhaskar
- Posted on: February 04 2004 04:32 EST
Threaded Messages (2)
- How can I know the calling class name ? by David Rabinowitz on February 04 2004 06:15 EST
- Use at your own risk: sun.reflect.Reflection by Sean Sullivan on February 04 2004 13:31 EST
-
How can I know the calling class name ?[ Go to top ]
- Posted by: David Rabinowitz
- Posted on: February 04 2004 06:15 EST
- in response to Udaya Bhaskar
Yes, but it is very expensive. Create new Throwable and check the stack trace. It is not recommended to use this except for debugging.
David -
Use at your own risk: sun.reflect.Reflection[ Go to top ]
- Posted by: Sean Sullivan
- Posted on: February 04 2004 13:31 EST
- in response to Udaya Bhaskar
In J2SE 1.4:
Undocumented class: sun.reflect.Reflection
Method: getCallerClass
sun.reflect.Reflection is NOT a standard API. Use at your own risk.