Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30573
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: closures |
| Date | 2014-12-16 13:08 +0100 |
| Message-ID | <cfalldFc5ksU1@mid.individual.net> (permalink) |
| References | <closures-20141212234123@ram.dialup.fu-berlin.de> <16bs8alknk9spc3tb69k0qt5ivgh3n6rli@4ax.com> |
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/
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
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
csiph-web