基本了解
这个注解对于强迫症的我简直太爽了!!!
作用: 给编译器一条指令,告诉它对被批注的代码元素内部的某些警告保持静默,即不再提示。
注解目标
类、字段、函数、函数入参、构造函数和函数的局部变量
示例说明
类上
@SuppressWarnings("all")
public class MyTest {
public static void main(String[] args) {
System.out.println("我这么欠揍,你来打我啊!");
}
}
变量上
public class MyTest {
@SuppressWarnings("all")
private String name="张三";
public static void main(String[] args) {
System.out.println("我这么欠揍,你来打我啊!");
}
}
参数介绍
参数 | 代表的含义 | mean |
---|---|---|
all | 'suppress all warnings' | ‘抑制所有警告’ |
boxing | 'suppress warnings relative to boxing/unboxing operations' | 抑制与装箱/拆箱操作相关的警告 |
cast | 'suppress warnings relative to cast operations' | 禁止与强制转换操作相关的警告 |
dep-ann | 'suppress warnings relative to deprecated annotation' | 禁止与已弃用注释相关的警告 |
deprecation | 'suppress warnings relative to deprecation' | 抑制与deprecation相关的警告 |
fallthrough | 'suppress warnings relative to missing breaks in switch statements' | 抑制与switch语句中缺少break相关的警告 |
finally | 'suppress warnings relative to finally block that don’t return' | 抑制相对于finally block不返回的警告 |
hiding | 'suppress warnings relative to locals that hide variable' | 抑制与隐藏变量的局部变量相关的警告 |
incomplete-switch | 'suppress warnings relative to missing entries in a switch statement (enum case)' | 抑制与switch语句中缺少条目相关的警告(enum情况) |
nls | 'suppress warnings relative to non-nls string literals' | 禁止与非nls字符串字面值相关的警告 |
null | 'suppress warnings relative to null analysis' | 抑制与null分析相关的警告 |
rawtypes | 'suppress warnings relative to un-specific types when using generics on class params' | 在类参数上使用泛型时,禁止与非特定类型相关的警告 |
restriction | 'suppress warnings relative to usage of discouraged or forbidden references' | 抑制与不鼓励或禁止引用的使用相关的警告 |
serial | 'suppress warnings relative to missing serialVersionUID field for a serializable class' | 抑制与可序列化类缺少serialVersionUID字段相关的警告 |
static-access | 'suppress warnings relative to incorrect static access' | 抑制与不正确静态访问相关的警告 |
synthetic-access | 'suppress warnings relative to unoptimized access from inner classes' | 抑制与内部类未优化访问相关的警告 |
unchecked | 'suppress warnings relative to unchecked operations' | 抑制与未选中操作相关的警告 |
unqualified-field-access | 'suppress warnings relative to field access unqualified' | 抑制有关字段访问不合格的警告 |
unused | 'suppress warnings relative to unused code' | 抑制相对于未使用代码的警告 |