Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: Why is that in JDK8: value used in lambda expression shuld be effectively final? Date: Sat, 05 Jan 2013 12:58:49 +0000 Organization: A noiseless patient Spider Lines: 18 Message-ID: <9lklr9-tk3.ln1@s.simpson148.btinternet.com> References: <9f030e71-96ab-4ead-9690-4369f4a19aa9@googlegroups.com> <0680c1e0-16cb-4791-8a5f-95a3ff2bcba8@googlegroups.com> <6f020a38-4566-4739-8ec7-a85d02a68d86@googlegroups.com> <0b4ba911-8f69-44a2-839c-ec3d2b002e8e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="9fa8d7cb0df1c78c19c94ab218768777"; logging-data="32453"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ovVIxZLj5DiX/bWzHX4wNwJLhPB11rQw=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <0b4ba911-8f69-44a2-839c-ec3d2b002e8e@googlegroups.com> Cancel-Lock: sha1:IOPB4q7k4N2GHpNBfPQBL1PWc4E= Xref: csiph.com comp.lang.java.programmer:20980 On 05/01/13 12:27, Saxo wrote: > Am Samstag, 5. Januar 2013 12:21:55 UTC+1 schrieb Steven Simpson: >> Sorry, but aren't these the same example that you originally gave, just >> in different languages? > No, because it works in all these languages what with JDK8 lambdas would only work if sum were declared final. I understand that they work in those languages, and that they don't work when directly translated into Java, because Java 'closures' lack a feature provided by the other languages. To put it another way, if you regard your original example as written in a fictional language similar to Java - one that supports MLC, and so doesn't throw an error back at you - it would be equivalent to each of the Groovy/Kotlin/Scala examples you listed. -- ss at comp dot lancs dot ac dot uk