View RSS Feed

My Java Tips

@SuppressWarnings annotation

Rate this Entry
by , 11-21-2011 at 05:34 PM (1500 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:
Java Code:
int a;
Object object = new Object();
I declared two variables and did not use them in my code. When I compiled the code, I got 2 warnings:

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;

Submit "@SuppressWarnings annotation" to Facebook Submit "@SuppressWarnings annotation" to Digg Submit "@SuppressWarnings annotation" to del.icio.us Submit "@SuppressWarnings annotation" to StumbleUpon Submit "@SuppressWarnings annotation" to Google

Comments