Fwd: lambda expression parameters
brian.goetz at oracle.com
Tue Dec 18 14:51:18 PST 2012
Imagine we were designing a language from scratch, knowing what we have
learned in the last 17 years about mutability being the root of all
evil. We would do many things to gently encourage people away from
Of all places to additionally discourage mutability as a way to do
things, and where it would likely have the least harm, lambda parameters
seem an obvious choice. The only reason we'd even consider letting them
be mutable is that Java already has methods that have parameters that
are mutable by default, and lambdas are like methods.
On 12/18/2012 5:41 PM, Remi Forax wrote:
> On 12/18/2012 11:33 PM, Brian Goetz wrote:
>> I like this suggestion that Venkat made on lambda-dev. However, it
>> would have to be a little more restrictive than that; basically, that
>> lambda parameters are *always* final. The only thing where I can
>> imagine this being an issue is in refactoring from inner classes, and
>> even there, if you are modifying method parameters, it is likely that
>> you need to do additional work to adapt this inner class to a lambda
>> So the suggestion is: lambda formals are always final.
>> What do people think?
> I don't see why parameter should be final. You explain a reason why they
> should not, but not why they should.
>> -------- Original Message --------
>> Subject: lambda expression parameters
>> Date: Tue, 18 Dec 2012 14:40:25 -0700
>> From: Venkat Subramaniam <venkats at agiledeveloper.com>
>> To: lambda-dev at openjdk.java.net <lambda-dev at openjdk.java.net>
>> Is there plans to make the inferred parameter of a lambda expression
>> final by default.
>> Right now, we can't specify the parameter is final unless we provide
>> it with the type.
>> In the spirit of leaning towards immutability, which is a better
>> practice, would it be possible to
>> (a) make all inferred parameters of lambda expressions final, and
>> (b) to make it non-final, force the developers to explicitly request
>> (like the mutable in F#).
>> It's more of a wish-list, if that's something that can be considered.
More information about the lambda-spec-observers