属性和对象报黄线怎么办

Pang_hao96 2018-01-10 10:15:58
在开发中,声明变量或者是new对象什么的,如果没有调用会报黄线,在程序里是不影响运行的,但是在上线时有可能会被扫描出bug,所以我们要尽可能的进行调用,也可以采用第二种方法:加注解 @SuppressWarings

@SuppressWarings注解 作用:用于抑制编译器产生警告信息。
其注解目标为类、字段、函数、函数入参、构造函数和函数的局部变量。而家建议注解应声明在最接近警告发生的位置。
示例1——抑制单类型的警告:
@SuppressWarnings("unchecked")
public void addArgues(String argue){
@SuppressWarnings("rawtypes")
List items = new ArrayList();
items.add(argue);
}
示例2——抑制多类型的警告:
@SuppressWarnings(value={"unchecked", "rawtypes"})
public void addArgues(String argue){
List items = new ArrayList();
items.add(argue);
}
示例3——抑制所有类型的警告:
@SuppressWarnings("all")
public void addArgues(String item){
List items = new ArrayList();
items.add(argue);
}

抑制警告的关键字                                
关键字 用途
all to suppress all warnings
相对于null分析来抑制警告

boxing to suppress warnings relative to boxing/unboxing operations
抑制警告相对于装箱/拆箱操作

cast to suppress warnings relative to cast operations
以抑制相对于转换操作的警告

dep-ann to suppress warnings relative to deprecated annotation
抑制警告相对过时的注释

deprecation to suppress warnings relative to deprecation
抑制警告相对贬值

fallthrough to suppress warnings relative to missing breaks in switch statements
禁止相对于开关语句中缺少的中断发出警告

finally to suppress warnings relative to finally block that don’t return
禁止相对于最后块不返回的警告。

hiding to suppress warnings relative to locals that hide variable
相对于隐藏变量的本地变量来抑制警告

incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case)
抑制警告相对缺少的条目在switch语句(枚举案例)

nls to suppress warnings relative to non-nls string literals
禁止相对于非NLS字符串字符串的警告

null to suppress warnings relative to null analysis
相对于null分析来抑制警告

rawtypes to suppress warnings relative to un-specific types when using generics on class params
联合国警告相对抑制特定类型时使用泛型类参数

restriction to suppress warnings relative to usage of discouraged or forbidden references
禁止有关使用气馁或禁止引用的警告

serial to suppress warnings relative to missing serialVersionUID field for a serializable class
抑制警告相对缺少serialVersionUID字段为可序列化类

static-access o suppress warnings relative to incorrect static access
o相对于不正确的静态访问抑制警告

synthetic-access to suppress warnings relative to unoptimized access from inner classes
抑制警告相对于未优化的访问内部类

unchecked to suppress warnings relative to unchecked operations
禁止相对于未检查的操作发出警告

unqualified-field-access to suppress warnings relative to field access unqualified
禁止相对于字段访问不合格的警告

unused to suppress warnings relative to unused code
禁止相对于未使用的代码发出警告
...全文
368 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
galiniur0u 2018-01-11
  • 打赏
  • 举报
回复
楼主可以用eclipse的提示看看黄线给出的是什么错误,然后根据错误修改,可能是未引用的变量、未引用的类包、强制转换未添加转换类型,编译器大部分会提示warn原因,根据原因改一下没有这个黄线了。
碧油唧 2018-01-10
  • 打赏
  • 举报
回复
只有几种可能 要么该属性没用到 要么错误警告

50,503

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧