当前位置:网站首页>有效的 @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"})
边栏推荐
猜你喜欢

Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly

The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)

程序员女友给我做了一个疲劳驾驶检测

报错:Plug-ins declaring extensions or extension points must set the singleton directive to true

Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)

Use of JMeter counters
![[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model](/img/05/85c004e4fbfc8d4984ac04ddb1190b.png)
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model

Complete knapsack problem

Download and installation configuration of cygwin

Deep learning | rnn/lstm of naturallanguageprocessing
随机推荐
Complete knapsack problem
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
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
How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars
Error: plug ins declaring extensions or extension points must set the singleton directive to true
409. longest palindrome
10. regular expression matching
MFC window scroll bar usage
318. 最大单词长度乘积
Blueprism registration, download and install -rpa Chapter 1
You cannot right-click F12 to view the source code solution on the web page
[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation
25.K个一组翻转链表
10. 正则表达式匹配
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
Implement pow (x, n) function
6. zigzag transformation
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline