by, 11-21-2011 at 04:34 PM (1390 Views)
In this post, I will be talking briefly about SuppressWarnings annotation.
Java compiler gives you warnings to assure that you know what is happening. Sometimes, you want donít want the warnings. Java 5.0 provides a way for this.
One had to use SuppressWarnings annotation to ignore the warnings. Annotations are followed by @.
For example: consider the following code:
I declared two variables and did not use them in my code. When I compiled the code, I got 2 warnings:Java Code:int a; Object object = new Object();
The local variable a is never read
The local variable object is never read
To remove the warnings, I will use the @SuppressWarnings annotation.
Java Code:@SuppressWarnings("unused") Object object = new Object(); @SuppressWarnings("unused") int a;