`
喜马拉雅上的小草
  • 浏览: 47725 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Supported Values for @SuppressWarnings & How to use @SuppressWarnings

 
阅读更多

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!

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
allDeprecation allJavadoc assertIdentifier boxing charConcat conditionAssign constructorName dep-ann deprecation discouraged emptyBlock enumSwitch,
incomplete-switch fallthrough fieldHiding finalBound finally forbidden hiding indirectStatic intfAnnotation intfNonInherited javadoc localHiding maskedCatchBlocks nls noEffectAssign null over-ann paramAssign pkgDefaultMethod raw semicolon serial specialParamHiding static-access staticReceiver suppress syntheticAccess,
synthetic-access tasks typeHiding unchecked unnecessaryElse unqualified-field-access,
unqualifiedField unused unusedArgument unusedImport unusedLabel unusedLocal unusedPrivate unusedThrown uselessTypeCheck varargsCast warningToken
deprecation even inside deprecated code
invalid or missing javadoc
occurrence of assert used as identifier
autoboxing conversion
when a char array is used in a string concatenation without being converted explicitly to a string
possible accidental boolean assignment
method with constructor name
missing @Deprecated annotation
usage of deprecated type or member outside deprecated code
use of types matching a discouraged access rule
undocumented empty block
incomplete enum switch
possible fall-through case
field hiding another variable
type parameter with final bound
finally block not completing normally
use of types matching a forbidden access rule
macro for fieldHiding, localHiding, typeHiding and maskedCatchBlock
indirect reference to static member
annotation type used as super interface
interface non-inherited method compatibility
invalid javadoc
local variable hiding another variable
hidden catch block
non-nls string literals (lacking of tags //$NON-NLS-<n>)
assignment with no effect
missing or redundant null check
missing @Override annotation
assignment to a parameter
attempt to override package-default method
usage a of raw type (instead of a parametrized type)
unnecessary semicolon or empty statement
missing serialVersionUID
constructor or setter parameter hiding another field
macro for indirectStatic and staticReceiver
if a non static receiver is used to get a static field or call a static method
enable @SuppressWarnings
when performing synthetic access for innerclass
enable support for tasks tags in source code
type parameter hiding another type
unchecked type operation
unnecessary else clause
unqualified reference to field
macro for unusedArgument, unusedImport, unusedLabel, unusedLocal, unusedPrivate and unusedThrown
unused method argument
unused import reference
unused label
unused local variable
unused private member declaration
unused declared thrown exception
unnecessary cast/instanceof operation
varargs argument need explicit cast
unhandled warning token in @SuppressWarnings
分享到:
评论

相关推荐

    How to use SFTP

    How to use SFTP (with client validation - public key authentication) The topic How to use SFTP (with client validation - password authentication) discusses the simplest form of client ...

    Designed for Use Create Usable Interfaces for Applications and the Web

    Idea chapters are concept-based: how to write usable text, how realistic your designs should look, when to use animations. Filled with illustrations and supported by psychological research, expert ...

    How to pair Intuos Creative Stylus in supported apps V6

    How to pair Intuos Creative Stylus in supported apps V6

    RemObjects SDK for Delphi

    Arrays Intermediate This sample shows how to use TROArray for presentating DB tables in a master/detail relationship. Async Introduction This sample shows how to call methods on a RemObjects SDK ...

    Beginning.Elastic.Stack

    This book teaches you how to install, configure and implement the Elastic Stack (Elasticsearch, Logstash and Kibana) – the invaluable tool for anyone deploying a centralized log management solution ...

    Kinect v2 Examples with MS-SDK v2.13 with SDK2.unitypackage

    The avatar-demo scenes show how to utilize Kinect-controlled avatars in your scenes, gesture-demos – how to use the programmatic or VGB gestures, fitting room demos – how to create your own dressing...

    解决no supported default etypes for default_tkt_enctypes问题,jce_policy-8.zip下载

    JAVA连接hive/hbase/sparksql/hdfs,kerbers认证失败 报no supported default etypes for default_tkt_enctypes ,需要更新jdk8的安全jar包,用来处理keytab文件,可以在oracle官网下,但是要注册账号,也可以下我的...

    Cross-platform.Localization.for.Native.Mobile.Apps.with.Xamarin

    How to use tools like Microsoft’s Multilingual App Toolkit to manage language resources How to create an localized, cross-platform app with Android Studio, Xcode, Xamarin and Visual Studio tools How ...

    Discover.the.aREST.Framework.1530779

    Each section also ends with a real world example to illustrate how you can use aREST for concrete projects. Table of Contents Chapter 1 Learning the basics of aREST Chapter 2 Build local ...

    Guidelines for designing COM Express™ Carrier Boards

    About This Document This document provides information for designing a custom system...refer also to the full specification – do not use this design guide as the only reference for any design decisions.

    JSON Quick Syntax Reference(Apress,2016)

    • What is and how to use the Object Definition Syntax supported in JSON • What comprises a JSON content production workflow • What are the concepts and principles behind the JSON Object ...

    Supported Configurations for Oracle WebLogic Server 10.3

    Supported Configurations for Oracle WebLogic Server 10.3

    CakePHP 1.3 Application Development Cookbook.pdf

    The last two recipes in this chapter give examples on how to use the Sluggable behavior (for creating SEO friendly URLs), and the Geocodable behavior (to add geocoding support to an Address model). ...

    TMS Advanced Charts 2.8

    Y-axis with auto ranging, minor & major value indication along Y-axis, multiple Y-axis values for different series supported Support for annotations & legend Panes with scrolling, scaling, splitter,...

    Microservice for the enterprise

    Concepts in the book are supported with use cases, and emphasis is put on the reality that most of you are implementing in a “brownfield” environment in which you must implement microservices ...

    Expert .NET Micro Framework

    Describes and compares wireless communication technologies and how to use them even if they are not directly supported by the .NET Micro Framework Describes the whole class library and features of ...

    uhdd.sys源码

    RAMdisk driver for use when resizing or other features are not needed UIDE is a DOS &quot;Universal IDE&quot; caching driver It intercepts &quot;Int 13h&quot; BIOS I O requests and caches data ...

    Pro Spring MVC With Web Flow

    What you'll learn Key Spring Framework fundamentals How to use the ...supported View Types How to customize your website What isand how to use the Spring Web Flow framework How to test your Spring MVC ...

    Mastering ROS for Robotics Programming - Second Edition[www.rejoiceblog.com].pdf

    Then, you will see how to use several APIs for vision and integrate OpenCV. Finally, the installation and usage of a visual odometry software is described. Chapter 10, Point Clouds, shows how to use ...

    Apache Hive Functions Cheat Sheet

    How to create and use Hive Functions, Listing of Built-In Functions that are supported in Hive

Global site tag (gtag.js) - Google Analytics