Effectively final effective?
Alex Blewitt
alex.blewitt at gmail.com
Thu Feb 25 00:21:24 PST 2010
On Thu, Feb 25, 2010 at 12:34 AM, Neal Gafter <neal at gafter.com> wrote:
> Scala and C# and Ruby programmers, and programmers in many other
> languages, live without this restriction. Perhaps we should ask them.
> In my experience it is a blessing compared to the Java alternatives.
Scala has 'val' and 'var', the former of which is final whilst the
latter is mutable. There is a strong preference for using 'val' where
possible in Scala programs (and in general, for creating immutable
objects).
Secondly, the fact that Scala can mutate captured variables (whereas
Java cannot, in the current version of the spec) is a key difference
between the two approaches. SImply omitting the keyword in Java does
not enable muation. So the question is not 'would you prefer them to
be mutable' but rather 'given that it is final, would you prefer to
explicitly declare that for less capable programmers to read later'.
Programs are written for other humans to understand, not for a
computer to understand.
Alex
More information about the lambda-dev
mailing list