Home > Mobile >  Call external variables in an anonymous inner class has increased since the subtraction operation, c
Call external variables in an anonymous inner class has increased since the subtraction operation, c

Time:10-11

Wrote a section of an anonymous inner class code, it invokes the external variables since the increase since decreases the operation, but must use the final modify the variable, otherwise the compiler complains, but with the final modify the variable, it would not be performed since the increase since decreases the operation, good solution this question?

CodePudding user response:

You can add new method of variable increases, the inner class call, since the decrease in the same way

CodePudding user response:

If it is a temporary variable in a method, can make an object, the variable assignment to that variable

CodePudding user response:

1, do not use local variables, using global variables;
2, instead of an array, for example: final int [] a={1}; A [0]=a [0] + 1;
  • Related