Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling owner of component

Status
Not open for further replies.

dwentink

Programmer
Apr 5, 2002
11
NL
Hi,

I have an object (Bal) that is contained by some other object (Field). Is it possible to call non-static methods of Field from the Bal owned by Field? In other words, is there a command to access the direct owner of an object?

thanx
Diederik
 
I don't think there is a way to access the owner of an object, I'm looking at the only possible package I know of that would allow this right now (java.lang.reflect) and I don't see anything. You could however get around this by passing the Field to the Ball in it's constructor or setting it via another Method, since Java uses pass by refrence for objects, you will be allowed to change the object there, if it's somewhere else just assign the object to a member object of the same type in the class, it'll still work.
 
Thanks, I think this is the best solution. I thought over the problem a bit further realize that a compiler could never resolve what is the owner of an object, so you can never directly call a method of an owner (except for methods in the class Object).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top