The final local variable cannot be assigned

前端 未结 6 1994
说谎
说谎 2020-11-29 23:48

I have an array of seats, and the array has two strings(selected and empty). On mouse click, I want to traverse the array and find the selected seat. When I press the button

6条回答
  •  悲哀的现实
    2020-11-30 00:19

    I recently faced similar problem. In my case it was easier to create final array (or collection) and to add variable, that I wanted to change inside anonymous class, to this array, as below.

       int a = 3;
       final int[] array = new int[1];
       array[0] = a;
       new Runnable() {
           @Override
           public void run() {
               array[0] += 3;
           }
       };
    

提交回复
热议问题