When I'm using lambda expressions or anonymous inner classes, with variables from outer class, I often get the compile time error:
local variables referenced from a lambda expression must be final or effectively final
local variables referenced from an inner class must be final or effectively final
Does compiler in java 8 interpret effectively final variables as final variables and later, in runtime use it as final?
The answer will be yes in both cases.
The reason for the latter is that the class file format does not provide a way to say whether a local variable is declared as
final. Therefore, if the JIT compiler is going to optimize based on finality, the finality must be inferred from what the bytecodes of a method actually do; i.e. effective finality.