@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:
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. @SuppressWarnings("unchecked")
void uncheckedGenerics() {
List words = new ArrayList();
words.add("hello"); // this causes unchecked warning
}XYZ.java uses unchecked or unsafe operations.
@SuppressWarnings("deprecation")
public void showDialog() {
JDialog dialog = new JDialog();
dialog.show(); // this is a deprecated method
} XYZ.java uses or overrides a deprecated API.
@SuppressWarnings({"unchecked", "deprecation"})
class Foo {
// code that may issue unchecked and deprecation warnings
} void foo(List inputList) {
@SuppressWarnings("unchecked")
List<String> list = (List<String>) inputList; // unsafe cast
}
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.