Best view in Firefox and Chrome

What is @SuppressWarnings Annotation in Java

Monday, June 7, 2010
Convert Article to PDFPrint ArticleEmail Article to FrinedBookmark this Article

SuppressWarnings is a Standard annotation for suppressing various warnings in Java. This functionality was included as a standard annotation from Java SE 5.

This annotation type gives the controling facility to programers on the warnings which are issued by the Java compiler. This SuppressWarnings intake a single element as an argument, but that is a array of String. The definition says, it can be use as like this @SuppressWarnings(value = {S1, ... , Sk})

After adding the @SuppressWarnings annotation.
Here Java compiler won't report any warning identified by one of S1, ... , Sk, when one of this waring would have been generated as a result of the annotated declaration or any of its parts.

What are the Valid Warning Types?

In the Sun JDK 1.5:
* all - This will suppress all warnings. @SuppressWarnings("all")

* deprecation - This will suppress warnings from using deprecated code@SuppressWarnings("deprecation")

* unchecked - This will suppress warnings from an unchecked call or an unchecked cast@SuppressWarnings("unchecked")

* fallthrough - This will suppress warnings if a switch falls through without finding a valid case (and no default). @SuppressWarnings("fallthrough")

* path - This will suppress warnings if it shows any path warings. @SuppressWarnings("path")

* serial - This will suppress warnings if a Serializable class does not define a serialVersionUID. @SuppressWarnings("serial")

* finally - This will suppress warnings from return within a finally (which will ignore return with the try). @SuppressWarnings("finally")

And Sun JDK 1.6 adds:
* cast
- This will suppress all cast warings. @SuppressWarnings("cast")

* divzero - suppress warnings if integer divide by zero is detected. @SuppressWarnings("divzero")

* empty - @SuppressWarnings("empty")

* overrides - @SuppressWarnings("overrides")

* none - @SuppressWarnings("none")

IDEs and static analysis tools . These values correspond to specific static analysis checks performed by the IDE.

Eclipse IDE also typically support a large number of other possible values for @SuppressWarnings.

* all - @SuppressWarnings("all") suppress all warnings

* boxing - @SuppressWarnings("boxing") suppress warnings relative to boxing/unboxing operations

* cast - @SuppressWarnings("cast") suppress warnings relative to cast operations

* dep-ann - @SuppressWarnings("dep-ann") suppress warnings relative to deprecated annotation

* deprecation - @SuppressWarnings("deprecation") suppress warnings relative to deprecation

* fallthrough - @SuppressWarnings("fallthrough") suppress warnings relative to missing breaks in switch statements

* finally - @SuppressWarnings("finally") suppress warnings relative to finally block that don't return

* hiding - @SuppressWarnings("hiding") suppress warnings relative to locals that hide variable

* incomplete-switch - @SuppressWarnings("incomplete-switch") suppress warnings relative to missing entries in a switch statement (enum case)

* nls - @SuppressWarnings("nls") suppress warnings relative to non-nls string literals

* null - @SuppressWarnings("null") suppress warnings relative to null analysis

* restriction - @SuppressWarnings("restriction") suppress warnings relative to usage of discouraged or forbidden references

* serial - @SuppressWarnings("serial") suppress warnings relative to missing serialVersionUID field for a serializable class

* static-access - @SuppressWarnings("static-access") suppress warnings relative to incorrect static access

* synthetic-access - @SuppressWarnings("synthetic-access") suppress warnings relative to unoptimized access from inner classes

* unchecked - @SuppressWarnings("unchecked") suppress warnings relative to unchecked operations

* unqualified-field-access - @SuppressWarnings("unqualified-field-access") suppress warnings relative to field access unqualified
v * unused - @SuppressWarnings("unused") suppress warnings relative to unused code

Read these Articles :


Why Breeze

This is a new technological rhythm in the web. It blooms like a Breeze in your technological face with more than 75 technoligical atricles and guidences.

Contact Me
Contact Me Send an Email Facebook Account LinkedIn profile Twitter/Shayanth
Share And Save
Social Share with Twitter Facebook Share Add to Google Save on Delicious
Get Updates

The RSS will facilitate you to get the updates from Breeze. Click Here to redirect to the RSS link.

Designed by Posicionamiento Web | Bloggerized by GosuBlogger | Blue Business Blogger | Customized by SHAUOM