今天打开Android Studio遇到下面这个警告:
This inspection searches for redundant class fields that can be replaced with local variables. If all local usages of a field are preceded by assignments to that field, the field can be removed and its usages replaced with local variables.
大概意思是:检测到这个变量可以使用局部变量替换,建议删除并写成局部变量。
解决方案:
删除private XXX XXX;
这句,并在使用的地方直接声明和实例化。
在 Android Studio for Mac
里可以直接使用快捷键 alt + enter
来快速转换成局部变量。