This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Caller reference? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Caller reference?" Watch "Caller reference?" New topic
Author

Caller reference?

Tom Elix
Greenhorn

Joined: Nov 03, 2002
Posts: 7
From a method in another object, how do I access the reference to the object who called me? In other words, how do I find the object which called this object?
Chloe Loh
Greenhorn

Joined: Aug 27, 2002
Posts: 22
I would pass the reference of the caller object into the mentioned method of the object that will be called. The declaration of the method in the class of the called object can be:
e.g. void calledMethod(Object calledObject)
I don't know if there is any more efficient way of doing it. but, if anyone have a better solution, I also want to learn it..
Chloe Loh
Greenhorn

Joined: Aug 27, 2002
Posts: 22
Sorry, I made a mistake.
The declaration of the method in the class of the called object can be:
e.g. void calledMethod(Object callerObject)
Wilfried LAURENT
Ranch Hand

Joined: Jul 13, 2001
Posts: 269
If you want this information for debugging purpose, you can also get it while writing this dirty code:

You will see all the stack, thus the caller .
W.
[ November 28, 2002: Message edited by: Wilfried LAURENT ]
 
wood burning stoves
 
subject: Caller reference?
 
Similar Threads
Subtract Minutes from a DateTime object
Deep copy of PriorityQueue class
Concurrent result set ?
garbage collection
Object self-replacement