Supported Values for @SuppressWarnings & How to use @SuppressWarnings
来源:互联网 发布:淘宝保证金是什么意思 编辑:程序博客网 时间:2024/05/29 14:04
Supported Values for @SuppressWarnings
http://jinchun1223.javaeye.com/blog/454140
http://www.breakitdownblog.com/supported-values-for-suppresswarnings/
Update #1: All these annotations are still valid in Eclipse 3.4 and 3.5, there have been no new SuppressWarning arguments added in those versions of the JDT compiler.
If you are a Java developer and use the new @SuppressWarnings annotation in your code from time-to-time to suppress compiler warnings you, like me, have wondered probably about a million times already just exactly what are the supported values that can be used with this annotation.
The reason the list isn’t easy to find is because it’s compiler specific, which means Sun may have a different set of supported values than say IBM, GCJ or Apache Harmony.
Fortunately for us, the Eclipse folks have documented the values they support (As of Eclipse 3.3), here they are for reference:
* all to suppress all warnings
* boxing to suppress warnings relative to boxing/unboxing operations
* cast to suppress warnings relative to cast operations
* dep-ann to suppress warnings relative to deprecated annotation
* deprecation to suppress warnings relative to deprecation
* fallthrough to suppress warnings relative to missing breaks in switch statements
* finally to suppress warnings relative to finally block that don’t return
* hiding to suppress warnings relative to locals that hide variable
* incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case)
* nls to suppress warnings relative to non-nls string literals
* null to suppress warnings relative to null analysis
* restriction to suppress warnings relative to usage of discouraged or forbidden references
* serial to suppress warnings relative to missing serialVersionUID field for a serializable class
* static-access to suppress warnings relative to incorrect static access
* synthetic-access to suppress warnings relative to unoptimized access from inner classes
* unchecked to suppress warnings relative to unchecked operations
* unqualified-field-access to suppress warnings relative to field access unqualified
* unused to suppress warnings relative to unused code
TIP: For the folks that haven’t used @SuppressWarnings before, the syntax looks like this:
@SuppressWarnings(”unused”)
and can be placed above almost any piece of code that is causing a compiler warning to popup for your class.
How to use @SuppressWarnings
Sometimes you will got the warning in Java when you are using the eclipse. And this is kind of annoying. Now you can use this to eliminate it:
@SuppressWarnings(option)
This can be categorized into two categories:
- Put this notation right before the code with warning:
- @SuppressWarnings("unused") String unused = "never";
- Put this notation right before the class declaration
- @SuppressWarnings("deprecation")
- class DeprecationExample{ ... }
I think the warning options in red should be categoried into category 2.
You can simply try this out!
allDeprecationSet warning level.
allJavadoc
assertIdentifier
boxing
charConcat
conditionAssign
constructorName
dep-ann
deprecation
discouraged
emptyBlock
enumSwitch
fallthrough
fieldHiding
finalBound
finally
forbidden
hiding
incomplete-switch
indirectStatic
intfAnnotation
intfNonInherited
javadoc
localHiding
maskedCatchBlocks
nls
noEffectAssign
null
over-ann
paramAssign
pkgDefaultMethod
raw
semicolon
serial
specialParamHiding
static-access
staticReceiver
suppress
synthetic-access
syntheticAccess
tasks(<task1>|...|<taskN>)
typeHiding
unchecked
unnecessaryElse
unqualified-field-access
unqualifiedField
unused
unusedArgument
unusedImport
unusedLabel
unusedLocal
unusedPrivate
unusedThrown
uselessTypeCheck
varargsCast
warningToken
e.g. -warn:unusedLocal,deprecation
In red are the default settings.
-warn:none disable all warnings -warn:<warnings separated by ,> enable exactly the listed warnings -warn:+<warnings separated by ,> enable additional warnings -warn:-<warnings separated by ,> disable specific warnings
incomplete-switch
synthetic-access
unqualifiedField
- Supported Values for @SuppressWarnings & How to use @SuppressWarnings
- Supported Values for @SuppressWarnings
- Supported Values for @SuppressWarnings
- Supported Values for @SuppressWarnings
- How to use @SuppressWarnings
- @SuppressWarnings
- @SuppressWarnings
- @SuppressWarnings
- SuppressWarnings
- @SuppressWarnings
- @SuppressWarnings
- @SuppressWarnings
- @SuppressWarnings()
- @SuppressWarnings
- SuppressWarnings
- @suppressWarnings
- @SuppressWarnings
- @suppresswarnings
- 多边形游戏(POJ 1179)
- 如何在Terminal下访问Oracle数据库
- Android Java获取当前时间的总结
- 数据库学习笔记–Database Design(1)
- 六招防止SQL注入式攻击
- Supported Values for @SuppressWarnings & How to use @SuppressWarnings
- s3c2440的USB主机控制器ED/TD
- Mysql常用命令
- java 匿名内部类
- MTK 读取MP3生成资源文件
- 数据库设计–Combination of Schemas
- C++有理数类Rational
- ServletContextListener Example
- 数据库学习笔记–Application Design and Development(1)