当前位置:网站首页>有效的 @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"})
边栏推荐
- 208. implement trie (prefix tree)
- 【JPCS出版】2022年第三届控制理论与应用国际会议(ICoCTA 2022)
- 【TA-霜狼_may-《百人计划》】2.1 色彩空间
- “目标检测“+“视觉理解“实现对输入图像的理解
- 【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
- 【TA-霜狼_may-《百人计划》】1.3纹理的秘密
- 392. judgment subsequence
- Pyramid scene parsing network [pspnet] thesis reading
- 165. 比较版本号
- All in one 1086: Jiaogu conjecture
猜你喜欢

Appium fundamentals of automated testing - basic principles of appium

Unexpected token o in JSON at position 1 ,JSON解析问题

TEC: Knowledge Graph Embedding with Triple Context
![[TA frost wolf \u may- hundred people plan] 1.3 secret of texture](/img/dc/ce2819258632cdcf2e130a4c05600e.png)
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture

【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型

Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)

Download and installation configuration of cygwin

431. encode n-ary tree as binary tree DFS

25.K个一组翻转链表

Appium自动化测试基础--补充:C/S架构和B/S架构说明
随机推荐
214. 最短回文串
Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
Libevent Library Learning
The preorder traversal of leetcode 144 binary tree and the expansion of leetcode 114 binary tree into a linked list
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
166. fractions to decimals
409. longest palindrome
“目标检测“+“视觉理解“实现对输入图像的理解
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
392. 判断子序列
jeecgboot输出日志,@Slf4j的使用方法
187. repeated DNA sequences
10、Scanner. Next() cannot read spaces /indexof -1
242. valid Letter heteronyms
Idea plug-in backup table
Jenkins自动清理构建历史
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
Unexpected token o in JSON at position 1 ,JSON解析问题
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎