# Excluding Warnings Using @SuppressWarnings

Since Java 5.0, you can disable compilation warnings relative to a subset of a compilation unit using the `java.lang.SuppressWarning` annotation.

     @SuppressWarning("unused") public void foo() {
      String s;
     }

Without the annotation, the compiler would complain that the local variable `s` is never used. With the annotation, the compiler silently ignores this warning locally to the `foo` method. This enables to keep the warnings in other locations of the same compilation unit or the same project.

The list of tokens that can be used inside a `SuppressWarnings` annotation is:

SuppressWarnings tokens
Token | Description | Suppressed compiler option(s)
--- | --- | ---
all | to suppress all warnings | All compiler options
boxing | to suppress warnings relative to boxing/unboxing operations | Boxing and unboxing conversions
cast | to suppress warnings relative to cast operations | Unnecessary cast or 'instanceof' operation
dep-ann | to suppress warnings relative to deprecated annotation | Missing '@Deprecated' annotation
deprecation | to suppress warnings relative to deprecation | Usage of deprecated API
exports | to suppress warnings relative to module API leaks | Public API exposes a type that is not exported Public API exposes a non-public type Public API exposes a type from another module that is not transitively required
fallthrough | to suppress warnings relative to missing breaks in switch statements | 'switch' case fall-through
finally | to suppress warnings relative to finally block that don't return | 'finally' does not complete normally
hiding | to suppress warnings relative to locals that hide variable | Local variable declaration hides another field or variable
incomplete-switch | to suppress warnings relative to missing entries in a switch statement (enum case) | Incomplete 'switch' cases on enum
javadoc | to suppress warnings relative to javadoc warnings | All options in Java Compiler Javadoc Preferences
module | to suppress warnings relative to modules | An automatic module has an unstable name
nls | to suppress warnings relative to non-nls string literals | Non-externalized strings
null | to suppress warnings relative to null analysis | All options in Java Compile Errors/Warnings Preferences for Null Analysis
preview | to suppress warnings relative to preview features | Use of a preview language feature Use of a preview API
rawtypes | to suppress warnings relative to usage of raw types | Usage of a raw type
removal | to suppress warnings relative to usage of terminally deprecated API | Usage of terminally deprecated API
resource | to suppress warnings relative to usage of resources of type Closeable | Resource leak Potential resource leak Resource not managed via try-with-resource Specification using '@Owning'/'@NotOwning' is insufficient
restriction | to suppress warnings relative to usage of discouraged or forbidden references | Forbidden reference (access rules) Discouraged reference (access rules)
serial | to suppress warnings relative to missing serialVersionUID field for a serializable class | Serializable class without serialVersionUID
static-access | to suppress warnings relative to incorrect static access | Non-static access to a static member Indirect access to a static member
static-method | to suppress warnings relative to methods that could be declared as static | Method can be static Method can potentially be static
super | to suppress warnings relative to overriding a method without super invocations |
synthetic-access | to suppress warnings relative to unoptimized access from inner classes |
sync-override | to suppress warnings because of missing synchronize when overriding a synchronized method | Missing synchronized modifier on inherited method
unchecked | to suppress warnings relative to unchecked operations | Unchecked generic type operation
unlikely-arg-type | to suppress warnings relative to unlikely argument types | Collection method with 'Object' parameter is called with an argument that may never match
unqualified-field-access | to suppress warnings relative to field access unqualified | Unqualified access to instance field

unused

to suppress warnings relative to unused code and dead code

Dead code
Unused object allocation
Value of local variable is not used
Value of method parameter is not used
Value of exception parameter is not used
Unused type parameter
Unused import
Unused private member
Unused 'break' or 'continue' label
Redundant super interface specification
Unnecessary specification of type arguments
Method declares 'throws' but exception is not thrown

### Related References

Java Compile Errors/Warnings Preferences