Effectively final effective?

Joshua Bloch jjb at google.com
Wed Feb 24 14:12:48 PST 2010


Alex,

On Wed, Feb 24, 2010 at 1:24 PM, Alex Blewitt <alex.blewitt at gmail.com>wrote:

> The Lambda 0.1.5 spec introduces 'effectively final', as a way of getting
> final-like variables but without having to type the letters f i n a l into
> the code.
>
> I'd argue that adding the keyword is no more or less difficult than it was
> when inner classes were introduced, and that modern IDEs will automatically
> prompt you to change the variable to final with a single click if used in an
> inner class.
>

I agree, but most people hate this aspect of anonymous classes, and we can
fix it. It's vaguely analogous to what we're doing with the "diamond
operator" (<>) for parametrized type instance creation.

It's not about how difficult it is to add the modifier final, but what it
does to the code. Seeing final, e.g., on a method parameter declaration so
that it can be passed to a "function object" (currently, an anonymous class
instance)  is visual noise. Of course this is a matter of taste, but I do
believe this represents the consensus opinion among Java programmers.

            Josh


More information about the lambda-dev mailing list