lambda expression parameters
Julian Hyde
julianhyde at gmail.com
Tue Dec 18 16:57:23 PST 2012
My opinion is that lambda parameters should be final by decree. For example, in
for (int i = 0; i < 10; i++) {
foo(i -> ++i);
}
the parameter 'i' to the lambda doesn't have a traditional declaration (such as 'int i' or 'final int i') and so a naive reader would be surprised to learn that it is actually different from the variable 'i' in the enclosing loop.
(Much the same issue as variables captured as members of anonymous inner classes.)
The compiler should give an error, and the naive reader would become a little less naive.
Julian
More information about the lambda-dev
mailing list