Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Annotation good practice  RSS feed

 
Manjusha Muraleedas
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a doubt...

I have a class A, which has 6 methods . two of showing unchecked warnings (generics).
I need to use




Is it good to use 'SuppressWarnings' for the two methods individually or declare 'SuppressWarnings' for the entire class....?

Regards,
Manjusha
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15865
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a good idea to keep the scope of the annotation as small as possible: put it only on the methods (or even the statements inside the method) where it's needed, and not on the entire class.

In fact, it's better to not use that annotation at all - see if there is a way to rewrite your code so that you don't have any unchecked casts in it. Only if there's no way to rewrite the code, use the annotation.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!