当前位置:网站首页>Valid @suppresswarnings warning name
Valid @suppresswarnings warning name
2022-07-01 03:59:00 【Blind scavenger】
1. Introduce
understand And @SuppressWarnings Java Different warning names used with annotations , It allows the compiler to suppress warnings . These warning names allow specific warnings to be suppressed . The available warning names depend on our IDE or Java compiler
2. Warning name
Here are @SuppressWarnings A list of valid warning names available in the annotation :
- all: This is a wildcard that prohibits all warnings
- boxing: Suppression and packing / Warnings related to unpacking operation
- unused: Warning against unused code
- cast: Suppress warnings related to object conversion operations
- deprecation: Suppress discard related warnings , For example, deprecated classes or methods
- restriction: Suppress warnings related to the use of discouraged or prohibited references
- dep-ann: Suppress warnings related to deprecated comments
- fallthrough: Inhibition and switch Missing in statement break sentence
- finally: Inhibition and finally Block related warnings , These blocks do not return
- hiding: Suppress and hide Warnings about locals of variables
- incomplete-switch: Inhibition and switch Missing entry related warning in statement *( enumeration * situation )
- nls: Inhibition and non nls String text related warnings
- null: Prohibition and null analysis
- serial: Inhibition and lack serialVersionUID Field related warnings , This field is usually in Serializable class
- static-access: Suppress warnings related to incorrect static variable access
- synthetic-access: Suppress warnings related to unoptimized access from inner classes
- unchecked: Warnings related to unchecked operations are prohibited
- unqualified-field-access: Suppress warnings related to unqualified field access
- javadoc: Inhibition and Javadoc Related warnings
- rawtypes: Suppress warnings related to using primitive types
- resource: Prohibition and use Closeable
- super: Super call In case of overriding method related warnings
- sync-override: In the cover Sync Method Suppression due to lack of Sync
3. Use warning name
Examples of using different warning names .
3.1.@SuppressWarnings(“unused”)
In the following example , Warning name suppresses Method Warnings for unused values in :
@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)
In the following example , Warning name prohibited *@deprecated* Method warning :
@SuppressWarnings("deprecated")
void suppressDeprecatedWarning() {
ClassWithSuppressWarningsNames cls = new ClassWithSuppressWarningsNames();
cls.deprecatedMethod(); // no warning here
}
@Deprecated
String deprecatedMethod() {
return "deprecated method";
}
3.3. @SuppressWarnings(“fallthrough”)
In the following example , The warning name suppresses the lack of break Warning for statement —— Include them here , Comment out , To display a warning :
@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”)
This warning name is at the class level . In the following example , Warning name suppresses Serializable Missing from class serialVersionUID( It has been commented out ) Warning of :
@SuppressWarnings("serial")
public class ClassWithSuppressWarningsNames implements Serializable {
// private static final long serialVersionUID = -1166032307853492833L; // no warning even though this is commented
4. Combine multiple warning names
@SuppressWarnings Comments need a String Array , So you can combine multiple warning names :
@SuppressWarnings({
"serial", "unchecked"})
边栏推荐
- Future of NTF and trends in 2022
- Go learning --- unit test subtest
- Grid system in bootstrap
- [TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
- 定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见
- 8. string conversion integer (ATOI)
- 10. 正则表达式匹配
- Unexpected token o in JSON at position 1 ,JSON解析问题
- 线程常用方法与守护线程
- Visit the image URL stored by Alibaba cloud to preview the thumbnail directly on the web page instead of downloading it directly
猜你喜欢

使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况

Idea plug-in backup table

熊市下的Coinbase:亏损、裁员、股价暴跌

京东智能客服言犀意图体系搭建和意图识别技术介绍

Huawei simulator ENSP - hcip - Hybrid Experiment 2

【TA-霜狼_may-《百人计划》】1.3纹理的秘密

Volley parsing data shows networking failure

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

分账技术赋能农贸市场,重塑交易管理服务效能

程序员女友给我做了一个疲劳驾驶检测
随机推荐
8. string conversion integer (ATOI)
187. repeated DNA sequences
Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
Error: plug ins declaring extensions or extension points must set the singleton directive to true
盘点华为云GaussDB(for Redis)六大秒级能力
Blueprism registration, download and install -rpa Chapter 1
72. edit distance
The problem of integrating Alibaba cloud SMS: non static methods cannot be referenced from the static context
187. 重复的DNA序列
214. minimum palindrome string
10. 正则表达式匹配
【JPCS出版】2022年第三届控制理论与应用国际会议(ICoCTA 2022)
Do280 management application deployment --rc
【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
How keil displays Chinese annotations (simple with pictures)
bootsrap中的栅格系统
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
HoloLens2开发环境搭建及部署app
[TA frost wolf _may - "hundred people plan"] 1.4 introduction to PC mobile phone graphics API
[ta- frost wolf \u may- hundred people plan] 2.2 model and material space