-
Notifications
You must be signed in to change notification settings - Fork 17
SuppressWarnings Annotation Examples
Ramesh Fadatare edited this page Aug 23, 2018
·
2 revisions
@SuppressWarnings Annotation indicates that the named compiler warnings should be suppressed in the annotated element (and in all program elements contained in the annotated element).
The @SuppressWarnings annotation type allows Java programmers to disable compilation warnings for a certain part of a program (type, field, method, parameter, constructor, and local variable). Normally warnings are good. However, in some cases, they would be inappropriate and annoying. So programmers can choose to tell the compiler ignoring such warnings if needed.
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
@Retention(RetentionPolicy.SOURCE)
public @interface SuppressWarnings {
/**
* The set of warnings that are to be suppressed by the compiler in the
* annotated element. Duplicate names are permitted. The second and
* successive occurrences of a name are ignored. The presence of
* unrecognized warning names is <i>not</i> an error: Compilers must
* ignore any warning names they do not recognize. They are, however,
* free to emit a warning if an annotation contains an unrecognized
* warning name.
*
* <p> The string {@code "unchecked"} is used to suppress
* unchecked warnings. Compiler vendors should document the
* additional warning names they support in conjunction with this
* annotation type. They are encouraged to cooperate to ensure
* that the same names work across multiple compilers.
* @return the set of warnings to be suppressed
*/
String[] value();
}
From above code, notice that @SuppressWarnings annotation applicable to field, method, parameter, constructor, and local variable
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})