Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Annotation good practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Annotation good practice" Watch "Annotation good practice" New topic

Annotation good practice

Manjusha Muraleedas
Ranch Hand

Joined: Jun 02, 2010
Posts: 52

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....?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
subject: Annotation good practice
Similar Threads
Type-safe list instantiation w/ reflection
Compiler warnings
add all selected data to datalist and send back to servlet
Please explain the meaning of this annotation
Why the need for two-step array initialization?