hg: lambda/lambda/jdk: Update initial lambda APIs and tests to use new syntax.
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Sep 12 03:27:43 PDT 2011
On 12/09/11 10:48, Rémi Forax wrote:
> 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.
Yeah - I know about that - the notion of effectively final only applied
to variables that have an initializer. There's a glitch between the
compiler and the current spec.
Maurizio
>
> 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