lambda expression parameters
Remi Forax
forax at univ-mlv.fr
Tue Dec 18 14:17:40 PST 2012
On 12/18/2012 10:40 PM, Venkat Subramaniam wrote:
> Hi
>
> 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.
Having local variable constant or not (exactly assigned once) is
orthogonal to having object immutable or not.
You can have an application with all local variables declared final with
all objects (except Strings) that are mutable and vice versa.
The only thing that is dangerous is if Java had allowed anonymous
classes and now lambda to capture local variable (the address) instead
of capturing its value.
Before Java 8, declaring a local variable final or not was more a coding
practice but in one case, when an anonymous class captures the value of
a variable.
In Java 8, you don't need to declare that local variable final any more,
because the compiler is able to see if this variable is final or not,
it's the effectively final rule. So there is no reason any more to
declare local variable final but to enforce a coding style.
>
> Thanks,
>
> Venkat
Rémi
More information about the lambda-dev
mailing list