views:

421

answers:

3

In Java, if you import a deprecated class:

import SomeDeprecatedClass;

You get this warning: The type SomeDeprecatedClass is deprecated

Is there a way to suppress this warning?

+1  A: 

Try using the following command-line switch when compiling:

-Xlint:-deprecation

the -Xlint switch lets you specify what warnings should be checked, prefacing one with a - explicitly disables it.

Amber
A: 

As a hack you can not do the import and use the fully qualified name inside the code.

You might also try javac -Xlint:-deprecation not sure if that would address it.

TofuBeer
+3  A: 

Use this annotation on your class or method:

@SuppressWarnings( "deprecation" )
craigforster
Does this work with imports? I've used that annotation on methods and such, but it doesn't seem to be recognized with imports.
Edward Mazur
Using the annotation at the class level should cover imports as well. It does this at least within Eclipse (well, Rational Application Developer) for me but I'm not sure about during command-line compilation.
craigforster
Ah yes, putting it at the class level did the trick (I'm using Eclipse as well). I'd only tried adding it above the imports, which did not work. Thank you!
Edward Mazur