Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: How does an inner class (non-static) refer to members of it's enclosing class?

Reply
Thread Tools

Re: How does an inner class (non-static) refer to members of it's enclosing class?

 
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      07-18-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Wolfgang) writes:

> What does that look like in practice?


In Sun's implementation all constructors of the inner class get passed
an extra parameter of the outer class' type, which is assigned to an
autogenerated variable called this$0.

> How does an inner class refer to members of it's enclosing class?


Via a "typed this", that is e.g. Outer.this.member, which is turned
into this$0.member by the compiler.

> And what happens when an inner class member has the same name as a
> member of the enclosing class?


The two are distinct because they are in different classes. When
resolving they follow normal namespace rules, that is an unqualified
reference will be the same as a this-reference, where this is the
inner-class type object.
 
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
referring to static fields of enclosing class from static inner class? bugbear Java 4 08-23-2006 08:26 AM
Referencing enclosing class from inner class Jonathan Java 3 07-31-2006 12:30 PM
Enclosing class instance availability during inner class initialization Stanimir Stamenkov Java 4 07-14-2006 01:13 PM
Accessing shadowed members of an enclosing class Bernd Fuhrmann Java 3 10-15-2005 09:36 PM
Re: How does an inner class (non-static) refer to members of it's enclosing class? Jayaram Java 0 07-18-2003 05:03 PM



Advertisments