IDEA告警:Field can be converted to a local varible

简介: IDEA告警:Field can be converted to a local varible

背景

使用 IDEA 开发时黄色预警:

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.

该变量在类中使用比较少,一般只在一个函数中使用,不需要创建一个全局变量,可以在调用该变量的函数中,使用时创建局部变量。

解决方案

按照上面的说法,可以对代码进行处理。例如:

修改前代码如下,由于mContext变量只是在构造函数中被调用,所以出现提示“Field can be converted to a local varible”

目录
相关文章
IDEA告警详解:Optional.isPresent can be replaced with functional-style expression
类似 if(Optional.isPresent()) 的条件语句,可以被重写成函数式风格。
162 0
IDEA告警详解:Optional.isPresent can be replaced with functional-style expression
|
存储 缓存 Java
IDEA告警:Unnecessary unboxing ‘xxx.intValue()‘
显式编码拆箱已包装的原始数值。在Java5及以上的版本,拆箱是不必要的,可以安全地删除。那么 JDK5 到底做了啥
179 0
|
Java 编译器 Spring
IDEA 出现问题:出现private field ‘xxx‘ is never assigned警告解决方案
IDEA 出现问题:出现private field ‘xxx‘ is never assigned警告解决方案
1257 0
IDEA 出现问题:出现private field ‘xxx‘ is never assigned警告解决方案
|
缓存 Java Maven
IDEA 告警:Library source does not match the bytecode for class
IDEA 告警:Library source does not match the bytecode for class
1343 0
IDEA 告警:Library source does not match the bytecode for class
取消IDEA的Autowired对字段注解告警
取消IDEA的Autowired对字段注解告警
187 0
取消IDEA的Autowired对字段注解告警
|
API
IDEA告警:Can be replaced with ‘.values().stream()‘
IDEA告警:Can be replaced with ‘.values().stream()‘
508 0
IDEA告警:Can be replaced with ‘.values().stream()‘
|
存储
IDEA 告警Unpredictable ‘new BigDecimal()‘ call
IDEA 告警Unpredictable ‘new BigDecimal()‘ call
360 0
|
API
IDEA 告警:Stream API call chain can be simplified
IDEA 告警:Stream API call chain can be simplified
196 0
|
4月前
|
Java 应用服务中间件 Maven
在IntelliJ IDEA中如何配置使用Maven以创建Tomcat环境
所以,别担心这些工具看起来有些吓人,实际上这些都是为了帮助你更好的完成工作的工具,就像超市里的各种烹饪工具一样,尽管它们看起来可能很复杂,但只要你学会用,它们会为你烹饪出一道道美妙的食物。这就是学习新技能的乐趣,让我们一起享受这个过程,攀登知识的高峰!
262 27
|
4月前
|
Java 应用服务中间件 Apache
在IntelliJ IDEA中使用Maven配置Tomcat环境
此配置方法具有较高的实用性,简单易懂。遵循以上步骤,您将能顺利在IntelliJ IDEA中使用Maven配置Tomcat环境,从而进行Web项目的开发和调试。
331 18