Suppressing Compile Warnings with Java Annotations
If you’ve used Java 1.5 Generics much then you’re probably familiar with the following compile warning: “Type safety: The expression of type List needs unchecked conversion to conform to List<String>” or similar. It turns out there’s a rather simple solution with annotations to ignore this problem:
@SuppressWarnings(“unchecked”)
A couple other possible uses of the annotation that might be of interest are:
@SuppressWarnings(“deprecation”)
@SuppressWarnings(“serial”)
These are compiler specific, so you may want to check out the full Eclipse list, which is a bit lengthier than Sun’s 7 options (all, deprecation, unchecked, fallthrough, path, serial, and finally).
Also, multiple statements can be combined into one as follows:
@SuppressWarnings({“unchecked”, “deprecation”})
Hi! I was surfing and found your blog post… nice! I love your blog. 🙂 Cheers! Sandra. R.
your post was a big help. I was wondering on how to suppress the warnings that are popping out at compile time and your post saved me a lot of time..