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.

This annotation type must be used with one or more warnings as its arguments, for example:

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "deprecation"})
List of warnings vary among Java compilers. The Java Language Specification mentions only “unchecked” warning (section 9.6.3.5). To see the list of warnings which would be issued by the Oracle’s Java compiler, type the following command:

javac -X

We’ll see the complete list of warnings after the line starts with -Xlint:{, as shown in the following screenshot:

list of warnings by Oracle Java compiler

So the warnings issued by Oracle’s Java compiler (as of Java 1.7) are: all, cast, classfile, deprecation, dep-ann, divzero, empty, fallthrough, finally, options, overrides, path, processing, rawtypes, serial, static, try, unchecked, varargs.

Different IDEs provide different list of warnings issued by their own compilers, e.g. list of suppress warnings provided by Eclipse IDE’s Java compiler.

Here are some of the most commonly used warnings which have same meaning across compilers: all, deprecation, unchecked.

 

Java @SuppressWarnings Examples:

 

Some Notes about @SuppressWarnings:

 

Other Annotations in Core Java:

 

Other Recommended Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.