Local variables referenced from a lambda expression must be final or effectively final
effectively final :
- A variable or parameter whose value is never changed after it is initialized
- If a reference is not changed it is effectively final even if the object referenced is changed.
- Any variable that is assigned once and only once, is “effectively final”.
In simple terms :
Imagine adding the final modifier to a variable declaration. If, with this change, the program continues to behave in the same way, both at compile time and at run time, then that variable is effectively final.
It looks like it is exact similar way. But only difference is no final keyword.
eg :
these are final
final int variable = 123;
final int number;
number = 23;
this is effective final
int variable = 123;
int number;
number = 34;
Fruther discussion :
Variables inside anonymous class must be final in outer class