Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #30568 > unrolled thread

Re: closures

Started byRoedy Green <see_website@mindprod.com.invalid>
First post2014-12-14 16:37 -0800
Last post2014-12-16 13:08 +0100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: closures Roedy Green <see_website@mindprod.com.invalid> - 2014-12-14 16:37 -0800
    Re: closures Robert Klemme <shortcutter@googlemail.com> - 2014-12-16 13:08 +0100

#30568 — Re: closures

FromRoedy Green <see_website@mindprod.com.invalid>
Date2014-12-14 16:37 -0800
SubjectRe: closures
Message-ID<16bs8alknk9spc3tb69k0qt5ivgh3n6rli@4ax.com>
On 12 Dec 2014 22:51:33 GMT, ram@zedat.fu-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

>
>  Today, I wanted to show to the students that inner classes cannot
>  modify fields of outer classes

You may be thinking about methods of an anonymous class can only
reference final local variables of the enclosing method.

see http://mindprod/jgloss/anonymousclasses.html
-- 
Roedy Green Canadian Mind Products http://mindprod.com
Software is a gas; it expands to fill its container.
~ Nathan Myhrvold (born: 1959-08-03 age: 55) Nathan’s First Law

[toc] | [next] | [standalone]


#30573

FromRobert Klemme <shortcutter@googlemail.com>
Date2014-12-16 13:08 +0100
Message-ID<cfalldFc5ksU1@mid.individual.net>
In reply to#30568
On 15.12.2014 01:37, Roedy Green wrote:
> On 12 Dec 2014 22:51:33 GMT, ram@zedat.fu-berlin.de (Stefan Ram)
> wrote, quoted or indirectly quoted someone who said :
>
>>   Today, I wanted to show to the students that inner classes cannot
>>   modify fields of outer classes
>
> You may be thinking about methods of an anonymous class can only
> reference final local variables of the enclosing method.

And, Stefan, note that "this" is final in the method, but members of 
"this" are not, of course.  Much the same way as in this example:

public final class Demo {

   public int counter;

   public static void main(String[] args) {
     final Demo d = new Demo();
     System.out.println(d.counter); // prints 0

     new Runnable() {
       @Override
       public void run() {
         ++d.counter;
       }
     }.run();

     System.out.println(d.counter); // prints 1
   }

}

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web