Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Dumb question: How do I get an object's parent?

Reply
Thread Tools

Dumb question: How do I get an object's parent?

 
 
El Guerrero del Interfaz
Guest
Posts: n/a
 
      06-09-2005
Hi,


I know it's a dumb question but then I'm newbie, so sorry about
that.

class MyObject {
anotherClass innerObject;
}
..
..
..
MyObject myObject = new MyObject();
..
..
..

What I want to do is how, knowing innerObject, do I get a reference
to the myObject instance that contains it? Is it possible?


Bye and thanks.




--
El Guerrero del Interfaz
 
Reply With Quote
 
 
 
 
Matt Humphrey
Guest
Posts: n/a
 
      06-09-2005

"El Guerrero del Interfaz" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed) om...
> Hi,
>
>
> I know it's a dumb question but then I'm newbie, so sorry about
> that.
>
> class MyObject {
> anotherClass innerObject;
> }
> .
> .
> .
> MyObject myObject = new MyObject();
> .
> .
> .
>
> What I want to do is how, knowing innerObject, do I get a reference
> to the myObject instance that contains it? Is it possible?


You put a reference to myObject inside of innerObject. The problem is that
there's no such thing as "parent" object. innerObject could be referenced
by any number (well, 1 or more) other objects, so if you want to go from
innerObject to myObject you must store that association somewhere (in
innerObject, in a separate object or index, by search, etc).

Cheers,
Matt Humphrey http://www.velocityreviews.com/forums/(E-Mail Removed) http://www.iviz.com/


 
Reply With Quote
 
 
 
 
Steve Horsley
Guest
Posts: n/a
 
      06-09-2005
El Guerrero del Interfaz wrote:
> Hi,
>
>
> I know it's a dumb question but then I'm newbie, so sorry about
> that.
>
> class MyObject {
> anotherClass innerObject;
> }
> .
> .
> .
> MyObject myObject = new MyObject();
> .
> .
> .
>


I believe that code running in methods of the inner object can
get at the outer instance by referring to "MyObject.this". e.g.

mummy = MyObject.this;

However, having a reference to the inner object doesn't help
unless a method of the inner object contains this code. You
really need the inner object's help in this respect.

I would query the need to find the outer object unless the inner
object is written to explicitly give you that information.

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dumb Question -- How do you get rid of Spaces in JSP Expression FormData? LB Java 5 07-09-2008 09:17 PM
Dumb, Dumb Vista Au79 Computer Support 4 02-11-2007 03:40 PM
Dumb, dumb dumb Qestion David Napierkowski Digital Photography 6 10-31-2004 11:14 PM
dumb newbie question (or newbie dumb question) Jerry C. Perl Misc 8 11-23-2003 04:11 AM
Can't get dumb webcounter working J. W. McCall Python 5 08-04-2003 01:59 PM



Advertisments