@SuppressWarnings annotation

7 March 2008

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:

int a;
Object object = new Object();

I declared two variables and did nto 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
</pre >.
 
To remove the warnings, I will use the @SuppressWarnings annotation.
 
<pre lang="java">
@SuppressWarnings("unused")
Object object = new Object();
@SuppressWarnings("unused")
int a;

del.icio.us:@SuppressWarnings annotation  digg:@SuppressWarnings annotation  spurl:@SuppressWarnings annotation  wists:@SuppressWarnings annotation  simpy:@SuppressWarnings annotation  newsvine:@SuppressWarnings annotation  blinklist:@SuppressWarnings annotation  furl:@SuppressWarnings annotation  reddit:@SuppressWarnings annotation  fark:@SuppressWarnings annotation  blogmarks:@SuppressWarnings annotation  Y!:@SuppressWarnings annotation  smarking:@SuppressWarnings annotation  magnolia:@SuppressWarnings annotation  segnalo:@SuppressWarnings annotation  gifttagging:@SuppressWarnings annotation

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: @SuppressWarnings annotation

Leave a Reply