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

Win a copy of Badass: Making Users Awesome this week in the Game Development 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: 14655

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 8 API documentation
I agree. Here's the link:
subject: Annotation good practice