当前位置:网站首页>有效的 @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"})
边栏推荐
- Jenkins自动清理构建历史
- 【TA-霜狼_may-《百人计划》】1.3纹理的秘密
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- What happens when a function is called before it is declared in C?
- Volley parsing data shows networking failure
- 【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
- Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
- 【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
- SEM of C language_ Tvariable type
- AfxMessageBox和MessageBox的用法
猜你喜欢
Blueprism registration, download and install -rpa Chapter 1
复习专栏之---消息队列
【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹
互联网行业最佳产品开发流程 推荐!
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
Pyramid scene parsing network [pspnet] thesis reading
Promql select time series
Sort linked list (merge sort)
TEC: Knowledge Graph Embedding with Triple Context
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
随机推荐
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
MFC窗口滚动条用法
【快捷键】
187. 重复的DNA序列
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹
All in one 1086: Jiaogu conjecture
166. fractions to decimals
8. string conversion integer (ATOI)
jeecgboot输出日志,@Slf4j的使用方法
PageObject模式解析及案例
Pytorch training deep learning network settings CUDA specified GPU visible
Database DDL (data definition language) knowledge points
166. 分数到小数
Review column - message queue
You cannot right-click F12 to view the source code solution on the web page
What does ft mean in the data book table
bootsrap中的栅格系统
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
208. implement trie (prefix tree)