Effectively Final Variables in Java
Java 8 introduced a new term : effectively final variables. A variable which is not declared as final but whose value is never changed after initialization is effectively final.
The above code does not compile, the java compiler gives the below error message for variable i.
To fix the compile error, loop variable i, which is not final can be assigned to an effectively final variable:
Java 8 compiler can detect that the variable counter remains unchanged and we can use a non-final local variable inside a lambda expression. If the value of the captured variable changes the compiler gives the same error as the above sample.