Suppressing Deprecation Warnings in Import Statements

I’ve got an import statement that references a deprecated class. However, it’s old and tested, and I don’t want to change it. For a long time, I annoyed the nagging warnings about such problems because there wasn’t anything I could do about them.

Along comes Java 1.5 with support for annotations (that’s attributes for you .NET folk). In particular, the SuppressWarnings attribute provides the ability to selectively disable warnings - precisely what I want.

So I’ve got something like this:

`package foo;

import old.package.OldClass;


@SuppressWarnings("deprecation") public class Bar { private OldClass iAmDeprecated; }

And everything works great, except for that pesky import statement. It still tosses a warning at me, and I can’t get it to go away! Putting the attribute into the file doesn’t work, either, because the SuppressWarnings attribute isn’t declared as a package annotation target.

For now, I’ve worked around the problem by removing the import and fully quaifying the class name in my code, but that’s lame. If anybody knows the “right” way to do this, please contact me.