@SuppressWarnings versus //noinspection
I am using IDEA 8.1.4. I have unchecked warnings turned on in my Errors settings.
When I have an unchecked warning and I click the option to "Suppress for Statement", sometimes IDEA inserts "//noinspection unchecked" before the statment and sometimes it inserts "@SuppressWarnings({"unchecked"})" at the beginning of the statement. I don't understand why it behaves differently in different classes. Is there a way that I can tell IDEA to always insert the annotation @SuppressWarnings?
Please sign in to leave a comment.
I may have an answer to my own question. I am a newbie when it comes to using Java annotations so I am just reporting my observations.
If I have a statement like this:
List<String> a = (List<String>)b.getSomething();
IDEA will insert @SuppressWarnings:
@SuppressWarnings({"unchecked"}) List<String> a = (List<String>)b.getSomething();
If I have a statement like this:
doSomething((List<String>)b.getSomething());
IDEA will disable the warning like this:
//noinspection unchecked
doSomething((List<String>)b.getSomething());
At the statement level, it looks like I can only apply the annotation to an assignment of a local variable. So I have to rewrite my statement to be something more like this:
@SuppressWarnings({"unchecked"}) List<String> a = (List<String>)b.getSomething();
doSomething(a);
ASAIK @SuppressWarnings annotation only works on Class and Method level
(plus some others by definition, but not on a statement @see
ElementType).
Idea adds the possibility of supressing inspection alerts on a per
statement level, which is very nice. But they had to introduce
something new, and it's the //noinspection "tag".
cheers
On 2009-11-26 07:06:58 +0900, Ed Hager <ed.hager@gmail.com> said:
very grateful for your help