Advantage of @SuppressWarnings annotation

the @SuppressWarnings annotation is for cleaner code, or does it add, is there any gain or any advantage?

or we can shorten the compilation time by doing this.


source to share

4 answers

Annotation type @SuppressWarnings

allows Java programmers to disable compilation warnings for a specific part of the program (type, field, method, parameter, constructor, and local variable). Usually warnings are good. However, in some cases, they would be inappropriate and annoying. Therefore, programmers can specify that the compiler ignores these warnings if necessary.

There is no relation to performance.

The developer who wrote the code knew it would always be safe and decided to use @SuppressWarnings ("unchecked") to suppress the compile-time warning.

As mentioned by others, it is simply a trust between the developer and the written code.

more details here and here




annotation is just suppressing warnings that you know are bound to happen and you are not interested in that. It just helps you do a cleaner check by suppressing the warnings you expect to see. No performance gain.



No performance, only on compilation the compiler will or won't write waring. However, after compilation, there is no difference.



It doesn't make your code cleaner or improve performance. It just helps to focus attention on potentially dangerous code. If you have a list of 130 warnings, you will soon stop reading them.

Most of the warnings are bad programming practices or potential problems that the compiler cannot solve. The finished program should, ideally, compile without warning. That way, when you change it and a new warning appears, you can decide what to do.

For example:

  • Unreachable code. What was I thinking here?
  • Lib ZZZ is deprecated. Should I upgrade to a new one? Can I continue this now?
  • Add type arguments for list ... ups, I have to use generics


All Articles