• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Class.this.. ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Class.this.. ?


  • Subject: Re: Class.this.. ?
  • From: Q <email@hidden>
  • Date: Wed, 29 Oct 2008 09:33:52 +1000


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@hidden
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@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Class.this.. ?
      • From: Florijan Stamenkovic <email@hidden>
References: 
 >Re: Class.this.. ? (From: Florijan Stamenkovic <email@hidden>)

  • Prev by Date: Re: Eclipse 3.4.1
  • Next by Date: Re: Eclipse 3.4.1
  • Previous by thread: Re: Class.this.. ?
  • Next by thread: Re: Class.this.. ?
  • Index(es):
    • Date
    • Thread