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!

 

Warning options
-warn:
allDeprecation
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
Set warning level.
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
allDeprecationdeprecation even inside deprecated code
allJavadocinvalid or missing javadoc
assertIdentifieroccurrence of assert used as identifier
boxingautoboxing conversion
charConcatwhen a char array is used in a string concatenation without being converted explicitly to a string
conditionAssignpossible accidental boolean assignment
constructorNamemethod with constructor name
dep-annmissing @Deprecated annotation
deprecationusage of deprecated type or member outside deprecated code
discourageduse of types matching a discouraged access rule
emptyBlockundocumented empty block
enumSwitch,
incomplete-switch
incomplete enum switch
fallthroughpossible fall-through case
fieldHidingfield hiding another variable
finalBoundtype parameter with final bound
finallyfinally block not completing normally
forbiddenuse of types matching a forbidden access rule
hidingmacro for fieldHiding, localHiding, typeHiding and maskedCatchBlock
indirectStaticindirect reference to static member
intfAnnotationannotation type used as super interface
intfNonInheritedinterface non-inherited method compatibility
javadocinvalid javadoc
localHidinglocal variable hiding another variable
maskedCatchBlockshidden catch block
nlsnon-nls string literals (lacking of tags //$NON-NLS-<n>)
noEffectAssignassignment with no effect
nullmissing or redundant null check
over-annmissing @Override annotation
paramAssignassignment to a parameter
pkgDefaultMethodattempt to override package-default method
rawusage a of raw type (instead of a parametrized type)
semicolonunnecessary semicolon or empty statement
serialmissing serialVersionUID
specialParamHidingconstructor or setter parameter hiding another field
static-accessmacro for indirectStatic and staticReceiver
staticReceiverif a non static receiver is used to get a static field or call a static method
suppressenable @SuppressWarnings
syntheticAccess,
synthetic-access
when performing synthetic access for innerclass
tasksenable support for tasks tags in source code
typeHidingtype parameter hiding another type
uncheckedunchecked type operation
unnecessaryElseunnecessary else clause
unqualified-field-access,
unqualifiedField
unqualified reference to field
unusedmacro for unusedArgument, unusedImport, unusedLabel, unusedLocal, unusedPrivate and unusedThrown
unusedArgumentunused method argument
unusedImportunused import reference
unusedLabelunused label
unusedLocalunused local variable
unusedPrivateunused private member declaration
unusedThrownunused declared thrown exception
uselessTypeCheckunnecessary cast/instanceof operation
varargsCastvarargs argument need explicit cast
warningTokenunhandled warning token in @SuppressWarnings

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值