Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: are lambdas a way to bring functional programming to java? Date: Tue, 01 Jul 2014 14:11:33 -0700 Organization: A noiseless patient Spider Lines: 58 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 1 Jul 2014 21:11:36 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="5aa64ebf9a53573f97c75abba936b0e2"; logging-data="875"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wFBVk6fe4tFSPIOG/tnJpDHY50JFlVEE=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Cancel-Lock: sha1:AlKhKtbqzo4yeOJAkihIh7cHFTU= Xref: csiph.com comp.lang.java.programmer:28892 On 7/1/2014 12:52 PM, Sebastian wrote: > it is not reasonable to say that "a lambda is just a terser > way to implement an instance of a one-use anonymous class" - except as a > first approximation that will serve you well in many circumstances. Right. It's often useful to think of them that way, but it isn't accurate. I think it also might be a bad way to introduce lambdas for new programmers. Old timers know what an anonymous inner class is. Newbies probably won't. (Hint for Roedy and his website.) > Here‘s a source for this claim: Stuart Marks answer at > http://stackoverflow.com/questions/15221659/java-8-lambda-expression-and-first-class-values > > from which I quote: > > > SNIP > ...Their behavior is essentially undefined... This is rather inaccurate. The *behavior* of lambdas is well defined. The *implementation* is left to the JVM. According to the video that Wanja posted, a lambda is just a single invoke-dynamic byte code, plus all the types and arguments captured thereby. That's both really well defined, and also not an inner class at all. If I understand that same video correctly, the guts of the example lambda presented were implemented by a private static method on the "parent" class, not a separate inner class, and so would have no distinct type at all. > As Brian Goetz has memorably put it (on lambda-dev): > "Lambdas-are-functions opens doors. Lambdas-are-objects closes them." Yeah, Brian Goetz has been emphasizing that the peculiarities of a lambda are for our benefit in the long run, in spite of criticism to the contrary. That goes for the lambdas-aren't-classes thing as well as lambdas-aren't-closures as well. I think people see something weird in Java that they don't understand, and they immediately think "it's generics again." Generics had some really unfortunate consequences, especially in the long run, that I don't think the expert group foresaw or completely understood. (In their defense, I'm sure they did as good as a job as possible at the time.) I don't blame folks for being nervous about new stuff introduced into Java, but I'm hopeful that the lambda expert group did a more thorough job researching possible consequences than what we got with generics. BTW, reifiable classes/types are on the list of things being looked at for Java 9. Keep your fingers crossed.