Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx02.iad.POSTED!not-for-mail From: Arved Sandstrom User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Java 8 closures vs. anonymous inner classes References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Lines: 47 Message-ID: <5yTqu.2639$oo4.861@fx02.iad> X-Complaints-To: abuse@newsgroups-download.com NNTP-Posting-Date: Sat, 14 Dec 2013 07:13:05 UTC Organization: Public Usenet Newsgroup Access Date: Sat, 14 Dec 2013 03:13:05 -0400 X-Received-Bytes: 2953 X-Received-Body-CRC: 4283151248 Xref: csiph.com comp.lang.java.programmer:26884 On 12/04/2013 03:07 PM, Sebastian wrote: > Someone made a passing comment in another thread to the effect that Java > 8 lambdas ("closures") were nothing but syntactic sugar for (anonymous) > inner classes. Here are a three differences: > > 1) lambdas can only instantiate "functional" (single abstract method) > interfaces I don't see this as being important. That's actually what Java lambdas are for, to provide a shorthand for instances of single-method classes. That's all they are for. > 2) lambdas have different scoping rules ("this" means different things) No argument here, the scoping is somewhat different. > 3) lambdas perform better due to the use of the invokedynamic JVM > instruction. Type representation, instance creation, and invocation > strategy are decided at runtime. This offers optimization potentials, > because evaluating a lambda expression need not create a new instance > each time. There could be „shared lambdas“ through use of a constant > static method in a constant pool, needing no new class and/or new object. To put it bluntly, who cares? The last time I ran into a speed bottleneck with any language was over a decade ago. The last time I ran into memory issues with any language was just this year, it happened to be Java, and the problem was easily solved by jacking up VM RAM - JVMs with most apps are somewhat of memory pigs, and I doubt that Java 8 lambdas are going to help much with that problem. > This is quite a bit more than what I'd call "syntactic sugar". > > -- Sebastian In a way they are just syntactic sugar. Most Java programmers will be unimpressed with your first point - if they don't completely miss it, they won't even (most of them) notice your second point (until it bites them and they sort of muddle through), and they won't even understand what the hell you are talking about wrt your third point: most developers work M-F 9-5 and don't have the time nor the inclination to get particularly good at their profession. AHS -- When a true genius appears, you can know him by this sign: that all the dunces are in a confederacy against him. -- Jonathan Swift