Combining multiple @SuppressWarnings annotations - Eclipse Indigo
Group all warnings you wish to suppress into one @SuppressWarnings
using an array:
Example:
Voila! This suppresses both the unchecked
and deprecation
warnings within myMethod()
.
Single and multiple warning suppression
Solo suppression
To suppress just one type of warning without needing braces is:
Example:
Avoid glaring "serial" warnings with this approach when you forget to declare a serialVersionUID
in a Serializable
class.
All in one go
Position your @SuppressWarnings
annotation above the declaration where the warning originates. This could be a class, method, or field declaration.
Method-level suppression :
Class-level suppression: Ideal when the same warnings stretch across multiple methods.
Note: Remember the scope of suppression. Class-level suppressions extend to all methods and fields within it. Be careful not to suppress warnings you didn't aim to in the first place.
Utilizing @SuppressWarnings to the fullest
When in Kotlin
If you're into the trendy Kotlin, use semicolons to mix warnings:
Example:
Pinpoint suppression
For finer control, utilize specific IDE tools to suppress only selective instances of warnings.
A balanced use
Although suppressing warnings is handy, yet ain't the solution to underlying problems causing the warnings. Resolve the root issues as much as possible.
Was this article helpful?