Bitten by the lambda parameter name
Brian Goetz
brian.goetz at oracle.com
Sat Sep 7 10:20:29 PDT 2013
Maybe! On the other hand, we wrote more than 20,000 lines of test code
for java.util.stream containing over 1000 lambdas, and didn't find any
such situations. (That's not to say everyone is going to code like me
-- YMMV. But these decisions were not made without data or experience.)
On 9/7/2013 12:54 PM, Esko Luontola wrote:
> Brian Goetz wrote on 7.9.2013 1:36:
>> True. But also realize that lambdas that declare locals are already
>> veering into corner-case territory. I did a quick search through lambda
>> expressions in the JDK source base (which is a significant fraction of
>> the lambda expressions in Java code worldwide, at this point), and found
>> NO instances of lambdas that declare locals.
>>
>> I'm not saying it can't or won't happen, I'm saying it will be rare.
>> So, this "but its also an issue for local variables in lambdas" argument
>> doesn't really change the balance on this subject at all. Next case!
>
> Here is an example of using local variables in lambdas: testing frameworks.
>
> If you look at Scala's testing frameworks (ScalaTest, specs, specs2),
> they wrap test code into lambdas (instead of methods) and there local
> variables are very common. And already now the Specsy testing framework
> [1] supports Java and results in lots of nested lambdas [2]. I believe
> that after JDK 8 is released, lambdas will change the way Java code is
> written and there will be lots of new use cases and libraries.
>
> [1] http://specsy.org/ - written by me
> [2] Its Java syntax is
> https://github.com/orfjackal/specsy/blob/master/specsy-java/src/test/java/org/specsy/java/JavaSpecsyExample.java
>
More information about the lambda-dev
mailing list