hg: lambda/lambda/jdk: Update initial lambda APIs and tests to use new syntax.
Rémi Forax
forax at univ-mlv.fr
Mon Sep 12 02:48:31 PDT 2011
On 09/12/2011 07:02 AM, Stuart Marks wrote:
> In the case of Mappers.instantiate(), I had to restore the 'final'
> declaration on the 'constructor' local variable. Without this
> declaration the compiler complained that this variable isn't
> effectively final. Hm, if code compiles and works with a variable
> declared 'final', and then the code is changed only by removing
> 'final', shouldn't that variable be effectively final? Maybe it's a
> compiler bug.
Yes, I think it's a compiler bug.
Maurizio, here is a small test case:
public class EffectivelyFinalLateInit {
public static void main(String[] args) {
String s;
s = "foo";
Runnable r = () -> { System.out.println(s); };
}
}
compiler output:
EffectivelyFinalLateInit.java:5: error: local variable s cannot be
referenced
Runnable r = () -> { System.out.println(s); };
^
local variables referenced from the body of a lambda expression must
be 'effectively final'
Rémi
More information about the lambda-dev
mailing list