On 29/10/2008, at 3:18 AM, Florijan Stamenkovic wrote:

Hi all,

Going a bit off WO topic here, but maybe it will be interesting to someone...

I've for the first time today found myself wishing to obtain a reference to the instance of a nesting class, while having a reference to an instance of it's inner class, but outside of the scope of the inner class itself... So, if I was in the scope of the inner class, I would simply do this:

NestingClass.this

and voila. However, since I am in a method in which I have an arbitrary instance of the inner class, let's call it "ref", I tried doing this:

NestingClass.ref

That would refer to a static variable called 'ref' on the class NestingClass.

This is a no-go. Now, as far as I understand the concept of class nesting as it is implemented in Java, this should work.

For inner classes there are two possible meanings for 'this', which is why the ClassName.this syntax exists, so that you can access both of them. Outside the context of an instance method on the inner class you cannot access the instance of the nesting class directly.

After all, it is simple to make a method in the inner class that will expose the instance of the nesting class by returning NestingClass.this.

This is what you will need to do.

So, I don't think this is a deliberate attempt to enforce some encapsulation concept, but an overlook, or something that was seen as an unnecessary syntactical complication. From my experience, either of those is in a way understandable, in some 4 years of working with Java I have only today for the first time wished to do this. Peculiar.

I will google this a bit, and depending on what I find might submit a bug report to Sun. Any thoughts on this are welcome....


--
Seeya...Q

Quinton Dolan - [EMAIL PROTECTED]
Gold Coast, QLD, Australia (GMT+10)
Ph: +61 419 729 806



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to