This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: nested inner classes and (this)


On Oct 2, 2010, at 2:13 AM, Per Bothner wrote:

On 10/01/2010 11:05 PM, Jamison Hope wrote:
Is there a way yet to refer to the outer class instance from within an
inner class (like
Java's "OuterClass.this" mechanism)? I see the website docs for the
(this) macro say
A planned extension will allow an optional class specifier (needed for
nested clases).

If I'm correctly interpreting thisRef.java and ThisExp.java, that hasn't
happened yet.
Are there any workarounds?

You could do something like:


(let ((outer-this (this)))
  ... outer-this ...)

Thanks, that seems to work. I see that right now, thisRef just looks for the implicit 'this' argument from the enclosing method, which means you can't use it with the new automatic SAM conversion:
(JButton text: "Click Me!"
action-listener:
(lambda (e) (format #t "This: ~A e: ~A~%" (this) e)))
fails to compile with the error "use of 'this' not in a named method". I'm not sure what to do about that (or even if it's worth doing anything about it).


But as far as extending it to accept a form "(this OuterClass)" - while the inner class is being compiled, does the Translator still have a reference to the outer class/method at all? Is it just stored in curMethodLambda (which gets overwritten in object.java), or is it also hidden in formStack or some other Translator instance variable?

Thanks,
Jamie

--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]