How to identify the odject name which is calling my method.

Hi All,I simply want to display the name of object which is using my method.I just want to write like-method(){System.out.println("Name of object which is using me is->"+ );}
[219 byte] By [sujeet_sharma_chandigarha] at [2007-11-27 4:39:52]
# 1
Objects don't have names.Thread.dumpStack().
ejpa at 2007-7-12 9:50:44 > top of Java-index,Core,Core APIs...
# 2
I'll try something like StackTraceElement[] trace = Thread.currentThread().getStackTrace(); System.out.println(trace[2].getClassName());trace[0] = Thread.getStackTrace()trace[1] = the actual methodtrace[2] = the calling method[]
S_i_m_ua at 2007-7-12 9:50:44 > top of Java-index,Core,Core APIs...
# 3

And be aware that it's possible that your method will be called from a static method of some class. In that case the object that is calling your method is that class.

And if it's called from an instance method of some object, you can't get a reference to that object. All you can know of it is its class name.

DrClapa at 2007-7-12 9:50:44 > top of Java-index,Core,Core APIs...