背景

使用 Android Studio 开发 Android 有一段时间了,偶尔会碰到 AS 在一些私有变量上有黄色高亮提示Field can be converted to a local varible,有些强迫症的我还是不希望看到这个黄色的高亮。百度没查到什么有用的信息,还是用谷歌搜到了一些解答。

解析

Field can be converted to a local varible 的完整说明是(纯手打):

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 来快速转换成局部变量。

PS:还是需要英语好点啊,实际上看说明就能明白了,就不用这样通过搜索才明白。

更多相关文章

  1. Android里面常用的Drawable的使用
  2. Android之MPAndroidChart库使用说明(柱状图、折线图、饼图和组合
  3. Mac上如何使用adb命令进行操作?(Android(安卓)studio 环境变量配置
  4. Android笔试(一)
  5. Android使用Application总结
  6. Android权限管理之Permission权限机制及使用
  7. AVD(android virtual device )路径设置
  8. Android(安卓)adb的使用略解
  9. [置顶] 一步一步学android OpenGL ES2.0编程(1)

随机推荐

  1. Android之Handler详解(四)
  2. Android LayoutInflater
  3. eclipse导入的Android项目没有android.ja
  4. Android面试系列文章2018之Android部分Ha
  5. Android SearchView 搜索框
  6. Android打印相关
  7. android:weight的使用
  8. Android(安卓)Gradle 插件中文指南
  9. Android设置显示文本
  10. Android 高级进阶之路 《总结篇》