| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| <head> |
| <meta name="copyright" content= |
| "Copyright (c) IBM Corporation and others 2000, 2017. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." /> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| <meta http-equiv="Content-Style-Type" content="text/css" /> |
| <link rel="STYLESHEET" href="../book.css" charset="ISO-8859-1" type="text/css" /> |
| <title>Excluding warnings using @SuppressWarnings</title> |
| <link rel="stylesheet" type="text/css" href="../book.css" /> |
| </head> |
| <body> |
| <a name="t_suppress_warnings"></a> |
| <h2>Excluding warnings using @SuppressWarnings</h2> |
| <p>Since Java 5.0, you can disable compilation warnings relative to a subset of a compilation unit using the <code>java.lang.SuppressWarning</code> annotation.</p> |
| |
| <pre> |
| @SuppressWarning("unused") public void foo() { |
| String s; |
| } |
| </pre> |
| <p>Without the annotation, the compiler would complain that the local variable <code>s</code> is never used. With the annotation, the compiler silently ignores this warning locally to the |
| <code>foo</code> method. This enables to keep the warnings in other locations of the same compilation unit or the same project.</p> |
| <p>The list of tokens that can be used inside a <code>SuppressWarnings</code> annotation is:</p> |
| |
| <ul> |
| <li><span class="token">all</span> to suppress all warnings</li> |
| <li><span class="token">boxing</span> to suppress warnings relative to boxing/unboxing operations</li> |
| <li><span class="token">cast</span> to suppress warnings relative to cast operations</li> |
| <li><span class="token">dep-ann</span> to suppress warnings relative to deprecated annotation</li> |
| |
| <li><span class="token">deprecation</span> to suppress warnings relative to deprecation</li> |
| <li><span class="token">fallthrough</span> to suppress warnings relative to missing breaks in switch statements</li> |
| <li><span class="token">finally</span> to suppress warnings relative to finally block that don't return</li> |
| <li><span class="token">hiding</span> to suppress warnings relative to locals that hide variable</li> |
| <li><span class="token">incomplete-switch</span> to suppress warnings relative to missing entries in a switch statement (enum case)</li> |
| |
| <li><span class="token">javadoc</span> to suppress warnings relative to javadoc warnings</li> |
| <li><span class="token">nls</span> to suppress warnings relative to non-nls string literals</li> |
| <li><span class="token">null</span> to suppress warnings relative to null analysis</li> |
| <li><span class="token">rawtypes</span> to suppress warnings relative to usage of raw types</li> |
| <li><span class="token">resource</span> to suppress warnings relative to usage of resources of type Closeable</li> |
| <li><span class="token">restriction</span> to suppress warnings relative to usage of discouraged or forbidden references</li> |
| |
| <li><span class="token">serial</span> to suppress warnings relative to missing serialVersionUID field for a serializable class</li> |
| <li><span class="token">static-access</span> to suppress warnings relative to incorrect static access</li> |
| <li><span class="token">static-method</span> to suppress warnings relative to methods that could be declared as static</li> |
| <li><span class="token">super</span> to suppress warnings relative to overriding a method without super invocations</li> |
| <li><span class="token">synthetic-access</span> to suppress warnings relative to unoptimized access from inner classes</li> |
| <li><span class="token">sync-override</span> to suppress warnings because of missing synchronize when overriding a synchronized method</li> |
| |
| <li><span class="token">unchecked</span> to suppress warnings relative to unchecked operations</li> |
| <li><span class="token">unqualified-field-access</span> to suppress warnings relative to field access unqualified</li> |
| <li><span class="token">unused</span> to suppress warnings relative to unused code and dead code</li> |
| </ul> |
| |
| <p>See also <a href="../reference/preferences/java/compiler/ref-preferences-errors-warnings.htm#annotations">Java Compile Errors/Warnings Preferences</a>.</p> |
| |
| </body> |
| </html> |