当前位置:网站首页>有效的 @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"})
边栏推荐
- Appium fundamentals of automated testing - basic principles of appium
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
- Online public network security case nanny level tutorial [reaching out for Party welfare]
- 【TA-霜狼_may-《百人计划》】1.2.1 向量基础
- [ta- frost wolf \u may- hundred people plan] 2.2 model and material space
- 10、Scanner. Next() cannot read spaces /indexof -1
- Bilinear upsampling and f.upsample in pytorch_ bilinear
- Usage of AfxMessageBox and MessageBox
- [TA frost wolf \u may- hundred people plan] 1.3 secret of texture
- Appium自动化测试基础--补充:C/S架构和B/S架构说明
猜你喜欢

Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period

Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)

SEM of C language_ Tvariable type

C语言的sem_t变量类型

Idea plug-in backup table

Libevent Library Learning

RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs

快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内

【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍

【TA-霜狼_may-《百人计划》】1.3纹理的秘密
随机推荐
【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
TEC: Knowledge Graph Embedding with Triple Context
Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period
使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
187. 重复的DNA序列
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
JMeter学习笔记2-图形界面简单介绍
Leetcode: offer 59 - I. maximum value of sliding window
程序员女友给我做了一个疲劳驾驶检测
在 C 中声明函数之前调用函数会发生什么?
线程常用方法与守护线程
165. 比较版本号
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
6. Z 字形变换
10. 正则表达式匹配
Network metering - application layer
Use of comment keyword in database
283.移动零
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
【TA-霜狼_may-《百人计划》】1.3纹理的秘密