How can I know the calling class name ?

Discussions

General J2EE: How can I know the calling class name ?

  1. How can I know the calling class name ? (2 messages)

    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).
  2. 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
  3. In J2SE 1.4:

    Undocumented class: sun.reflect.Reflection

    Method: getCallerClass

    sun.reflect.Reflection is NOT a standard API. Use at your own risk.