Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining multiple @SuppressWarnings annotations - Eclipse Indigo

People also ask

What is SuppressWarnings annotation?

The SuppressWarning annotation is used to suppress compiler warnings for the annotated element. Specifically, the unchecked category allows suppression of compiler warnings generated as a result of unchecked type casts.

What is @SuppressWarnings Rawtypes?

If you choose to put @SuppressWarnings("rawtypes") at the method level, Eclipse will suppress all raw-types warnings inside that method. If we compile same code without @SuprressWarnings, using javac compiler it will show the following hint: $ javac RawType.

What does @SuppressWarnings mean in Java?

Use of @SuppressWarnings is to suppress or ignore warnings coming from the compiler, i.e., the compiler will ignore warnings if any for that piece of code. 1. @SuppressWarnings("unchecked") public class Calculator { } - Here, it will ignore all unchecked warnings coming from that class.

What is @SuppressWarnings resource?

Adding the @SuppressWarnings({ "resource" }) should remove the warning for a potential resource leak. Adding a list for other ones, it's for Eclipse but they should be fairly similar for reference.


Use the following: @SuppressWarnings({"unused", "unchecked"})


If you take a look inside the annotation you will see this:

public @interface SuppressWarnings {
    String[] value();
}

as you see, the value parameter is an array of Strings... so the parameter in the annotation can be: value1, value2 or value3 where

final String[] value1 = { "a1" };
final String[] value2 = { "a1", "a2" };
final String[] value3 = { "a1", "a2", "a3" };

i.e.:

@SuppressWarnings({"unused"})
@SuppressWarnings({"unused", "javadoc"})

you can oft see something like

@SuppressWarnings("unused") 

and this is a particular case allowing one element wit no "{ }"