Summary:java.lang.SuppressWarnings is one of the annotation standard in J2SE 5.0. Can be labeled on classes, fields, methods, parameters, construction methods, and local variables. function: tells the compiler to ignore the specified warning and not to have a warning message after the compilation is complete.
Use:
@SuppressWarnings ("")
@SuppressWarnings ({})
@SuppressWarnings (value={})
according to Sun's Official document description:
Value-the set of warnings that will be deselected by the compiler in the elements of the annotation. Duplicate names are allowed. Ignores the second and subsequent names. An unrecognized warning name is not an error: The compiler must ignore all unrecognized warning names. However, if a comment contains an unrecognized warning name, the compiler can issue a warning at will.
Each compiler vendor should record the warning names they support along with the annotation types. Encourage collaboration among vendors to ensure that the same name is used in multiple compilers.
Example:
· @SuppressWarnings ("Unchecked")
tells the compiler to ignore unchecked warning messages, such as warnings that are not parameterized using list,arraylist.
· @SuppressWarnings ("Serial")
If the compiler appears with this warning message: The serializable class Wmailcalendar does not declare a static final serialversionuid field of type long
Use this comment to remove the warning message.
· @SuppressWarnings ("deprecation")
If you use a method that uses @Deprecated annotations, the compiler appears with a warning message.
Use this comment to remove the warning message.
· @SuppressWarnings ("Unchecked", "deprecation")
tells the compiler to ignore both unchecked and deprecation warning messages.
· @SuppressWarnings (value={"Unchecked", "deprecation"})
equivalent to @SuppressWarnings ("Unchecked", "deprecation")
1. Suppress single-type warnings
1 @SuppressWarnings ("Unchecked")2publicvoid additems (String item {3 @SuppressWarnings ("Rawtypes")4 new ArrayList (); 5 Items.Add (item); 6 }
2. Suppress multi-type warnings
@SuppressWarnings (value={"Unchecked", "Rawtypes"})publicvoid additems (String Item) { new ArrayList (); Items.Add (item);}
3. Suppress all warnings
1 @SuppressWarnings ("All")2publicvoid Additems (String Item) {3 new ArrayList (); 4 Items.Add (item); 5 }
Annotation target
by @SuppressWarnings Source, the annotated target is a local variable of class, field, function, function parameter, constructor and function. The home recommendation note should be declared at the location closest to where the warning occurred.
Suppress Warnings for keywords
Key words |
Use |
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-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 |
Rawtypes |
To suppress warnings relative to un-specific types if using generics on class params |
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 |
o 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
|
@SuppressWarnings Ignore warnings