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: 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 I'm currently plaing with JDK8 and using lambda-8-b69-windows-i586-17_dec_2012. I wonder why this does not compile: List 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