Compiler Error J0207

Cannot assign blank final variable 'identifier' in a loop

The compiler detected that a final variable was assigned a value from within the scope of a program control loop. A final variable can only be assigned a value once and thus cannot be initialized within a loop. Move the initialization of the final variable specified in the error message outside of the loop and ensure that it is initialized only once.

The following example illustrates this error:

public class Simple{
   final int x;
   
   public Simple(){
      for (int z=0;z<10;z++){
         x = z; /*error: cannot assign final variable
                  in loop */
      }
   }
}