I have a good trick for you: *IF* the thing you want to suppress
warnings on can be limited to a single expression, this works just
fine:
@SuppressWarnings("unsafe") List<String> x = (List<String>) someList;
It has to be a variable declaration though, not just an assignment.
Only declarations can legally be annotated. Still, useful quick hack
to limit the scope of a @SuppressWarnings.
On Sep 25, 11:18 am, Richard Fearn <[email protected]> wrote:
> On 23 September 2010 22:39, Reinier Zwitserloot <[email protected]> wrote:
>
> > @SuppressWarnings("throws") is a bit drastic as now ANY omission of
> > handling a checked exception anywhere in this code is going to go by
> > unnoticed, and it also doesn't help readability because it doesn't
> > list which particular kind of exception I'm actively going to ignore.
>
> This is a good point. I occasionally remind people that shoving
> @SuppressWarnings("something") to the top of a 200-line method is
> asking for trouble, because it causes *all* warnings of that type to
> be ignored.
>
> I've sometimes gone as far as to move one or two lines of code into a
> new method just so that @SuppressWarnings can be added to that method,
> instead of a larger method. Keeping the scope of an @SuppressWarnings
> as small as possible is a good idea.
>
> Of course, removing @SuppressWarnings altogether is even better :-)
>
> Rich
--
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.