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?
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).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.