aspose file tools*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Annotation good practice" Watch "Annotation good practice" New topic
Author

Annotation good practice

Manjusha Muraleedas
Ranch Hand

Joined: Jun 02, 2010
Posts: 52
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Annotation good practice
 
Similar Threads
Compiler warnings
Please explain the meaning of this annotation
Why the need for two-step array initialization?
Type-safe list instantiation w/ reflection
add all selected data to datalist and send back to servlet