Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: new Java lambda syntax Date: Sun, 11 Sep 2011 20:14:05 +0100 Organization: Aioe.org NNTP Server Lines: 54 Message-ID: References: <9j3vj8-aqe.ln1@news.simpsonst.f2s.com> NNTP-Posting-Host: r+C7JLFxs5GRD6HZueZLYg.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Lightning/1.0b2 Thunderbird/3.1.13 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7815 On 11/09/11 19:08, BGB wrote: > I would have also liked to see lexical variable capture. > FFS, I added this (along with closures) to a C compiler before, can't > be too hard At this stage, I don't think the issue is how, but whether/when to permit it. All suggestions for how seem to come down to boxing: * arrays of length 1 * hidden local classes * AtomicInteger, etc (If there were any others, I didn't understand them.) The options for when/whether have been: * never * always * when a local is tagged with @Shared, public or similar * when the SAM parameter is tagged with @Callback, @Block or similar They've gone for 'never' because it's sufficient to meet their primary goals of supporting concurrent APIs, especially on collections, and they want to encourage good concurrent practices. They can still look at the other options later - it would be harder to withdraw an advanced feature, having discovered it was a bad idea. > having spent more of my time using languages with much nicer > first-class functions (yes, I will include C here, as well as > JavaScript and similar...), having to have extra syntax (both to > declare and use these types) is IMO lame. > > in all cases, one would type "obj(args)". > > idiomatic for Java or not, the more compact declarations and > invocations are more what people who use most other languages are > likely to expect (and ideally the compiler can be smart enough to > figure out what "obj(args)" with a SAM means). Lambda declarations are already quite compact, with type inference helping in most cases. new Thread(() -> { doSomething(); }).start(); // Runnable implied For invocations, having to type obj.run() instead of obj() is hardly onerous. Plus, invocations will be much rarer than lambda declarations. Also note that the invocation site is unaware of whether the object is a lambda. -- ss at comp dot lancs dot ac dot uk