Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #20869
| X-Received | by 10.224.190.193 with SMTP id dj1mr25435623qab.6.1357131064639; Wed, 02 Jan 2013 04:51:04 -0800 (PST) |
|---|---|
| Received | by 10.49.34.135 with SMTP id z7mr6967068qei.1.1357131064577; Wed, 02 Jan 2013 04:51:04 -0800 (PST) |
| Path | csiph.com!aioe.org!news.glorb.com!ee4no11686830qab.0!news-out.google.com!k2ni3609qap.0!nntp.google.com!ee4no11571599qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.java.programmer |
| Date | Wed, 2 Jan 2013 04:51:04 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=95.116.88.210; posting-account=QuOrbQoAAADk1Ytmd4kkfWK7_Nh1pnw_ |
| NNTP-Posting-Host | 95.116.88.210 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <c885bedb-977c-49b4-a10a-b9cdd3df1dd9@googlegroups.com> (permalink) |
| Subject | Why is that in JDK8: value used in lambda expression shuld be effectively final? |
| From | jeti789@web.de |
| Injection-Date | Wed, 02 Jan 2013 12:51:04 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.java.programmer:20869 |
Show key headers only | View raw
I'm currently plaing with JDK8 and using lambda-8-b69-windows-i586-17_dec_2012. I wonder why this does not compile:
List<Integer> ints = new ArrayList<>();
ints.add(1);
ints.add(2);
ints.add(3);
int sum = 0;
ints.forEach(i -> {sum += i;});
The compiler error is "value used in lambda expression shuld be effectively final"
However, this here compiles:
int sumArray[] = new int[] { 0 };
ints.forEach(i -> {sumArray[0] += i;});
I'm a bit confused now. Does this mean that JDK8 closures are no true closures or is this a bug in my IDE (IDEA 12)?
Thanks, Oliver
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
Why is that in JDK8: value used in lambda expression shuld be effectively final? jeti789@web.de - 2013-01-02 04:51 -0800
Re: Why is that in JDK8: value used in lambda expression shuld be effectively final? Steven Simpson <ss@domain.invalid> - 2013-01-02 14:15 +0000
Re: Why is that in JDK8: value used in lambda expression shuld be effectively final? Robert Klemme <shortcutter@googlemail.com> - 2013-01-07 23:08 +0100
Re: Why is that in JDK8: value used in lambda expression shuld be effectively final? Saxo <jeti789@web.de> - 2013-01-02 09:46 -0800
Re: Why is that in JDK8: value used in lambda expression shuld be effectively final? Saxo <jeti789@web.de> - 2013-01-05 07:01 -0800
csiph-web