当前位置:网站首页>有效的 @SuppressWarnings 警告名称
有效的 @SuppressWarnings 警告名称
2022-07-01 03:36:00 【盲目的拾荒者】
1.介绍
了解 与@SuppressWarnings Java 注解一起使用的不同警告名称,它允许编译器抑制警告。 这些警告名称允许抑制特定的警告。 可用的警告名称取决于我们的 IDE 或 Java 编译器
2. 警告名称
以下是@SuppressWarnings 注解中可用的有效警告名称列表:
- all: 这是一种禁止所有警告的通配符
- boxing: 抑制与装箱/拆箱操作相关的警告
- unused: 禁止未使用代码的警告
- cast: 抑制与对象转换操作相关的警告
- deprecation: 抑制与弃用相关的警告,例如弃用的类或方法
- restriction: 抑制与使用不鼓励或禁止引用有关的警告
- dep-ann: 抑制与弃用注释相关的警告
- fallthrough: 抑制与switch语句中缺少break语句
- finally: 抑制与finally块相关的警告,这些块不会返回
- hiding: 抑制与隐藏变量的本地人相关的警告
- incomplete-switch: 抑制与switch语句中缺失条目相关的警告*(枚举*情况)
- nls: 抑制与非 nls 字符串文字相关的警告
- null: 禁止与null分析
- serial: 抑制与缺少的serialVersionUID字段相关的警告,该字段通常在Serializable类
- static-access: 抑制与不正确的静态变量访问相关的警告
- synthetic-access: 抑制与来自内部类的未优化访问相关的警告
- unchecked: 禁止与未经检查的操作相关的警告
- unqualified-field-access: 抑制与不合格字段访问相关的警告
- javadoc:抑制与 Javadoc 相关的警告
- rawtypes: 抑制与使用原始类型相关的警告
- resource: 禁止与使用Closeable
- super: 超级调用 的情况下覆盖方法相关的警告
- sync-override: 在覆盖同步方法 抑制由于缺少同步
3. 使用警告名称
使用不同警告名称的示例。
3.1.@SuppressWarnings(“unused”)
在下面的示例中,警告名称抑制了方法中未使用值的警告:
@SuppressWarnings("unused")
void suppressUnusedWarning() {
int usedVal = 5;
int unusedVal = 10; // no warning here
List<Integer> list = new ArrayList<>();
list.add(usedVal);
}
3.2. @SuppressWarnings(“deprecated)
在下面的示例中,警告名称禁止使用*@deprecated*方法的警告:
@SuppressWarnings("deprecated")
void suppressDeprecatedWarning() {
ClassWithSuppressWarningsNames cls = new ClassWithSuppressWarningsNames();
cls.deprecatedMethod(); // no warning here
}
@Deprecated
String deprecatedMethod() {
return "deprecated method";
}
3.3. @SuppressWarnings(“fallthrough”)
在下面的示例中,警告名称抑制了缺少break语句的警告——将它们包含在这里,注释掉,以显示警告:
@SuppressWarnings("fallthrough")
String suppressFallthroughWarning() {
int day = 5;
switch (day) {
case 5:
return "This is day 5";
// break; // no warning here
case 10:
return "This is day 10";
// break; // no warning here
default:
return "This default day";
}
}
3.4. @SuppressWarnings(“serial”)
此警告名称位于类级别。在下面的示例中,警告名称抑制了Serializable类中缺少的serialVersionUID(已将其注释掉)的警告:
@SuppressWarnings("serial")
public class ClassWithSuppressWarningsNames implements Serializable {
// private static final long serialVersionUID = -1166032307853492833L; // no warning even though this is commented
4. 组合多个警告名称
@SuppressWarnings注释需要一个String数组,因此可以组合多个警告名称:
@SuppressWarnings({
"serial", "unchecked"})
边栏推荐
猜你喜欢

MFC window scroll bar usage

在线公网安备案保姆级教程【伸手党福利】
![[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions](/img/be/325f78dee744138a865c13d2c20475.png)
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
![[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation

Appium自动化测试基础--补充:C/S架构和B/S架构说明

Millet College wechat scanning code login process record and bug resolution
![[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation](/img/4e/8cf60bc816441967c04f97c64685a1.png)
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation

[TA frost wolf \u may - "hundred people plan"] 2.1 color space

Addition without addition, subtraction, multiplication and division

MFC窗口滚动条用法
随机推荐
10、Scanner. Next() cannot read spaces /indexof -1
程序员女友给我做了一个疲劳驾驶检测
Blueprism registration, download and install -rpa Chapter 1
4. [WebGIS practice] software operation chapter - data import and processing
MFC window scroll bar usage
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
jeecgboot输出日志,@Slf4j的使用方法
431. encode n-ary tree as binary tree DFS
Jeecgboot output log, how to use @slf4j
206.反转链表
72. edit distance
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹
72. 编辑距离
Leetcode:829. Sum of continuous integers
409. longest palindrome
[shortcut key]
C语言的sem_t变量类型
[party benefits] jsonobject to string, leave blank
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture