How can I suppress javac warnings about deprecated api?

Solution 1:

From what I can tell in the docs, you can't do it on the command-line.

According to the javac documentation, -Xlint:none only disables warnings "not mandated by the Java Language Specification". It appears that warning you of the use of deprecated APIs is managed by the language spec.

Your best option would be to fix the use of deprecated APIs. However, an option would be to add the @SuppressWarnings("deprecation") annotation to the classes or methods that are using the deprecated APIs.

Solution 2:

Two possible ways:

  1. don't use deprecated API
  2. Use @SuppressWarnings("deprecation")

Solution 3:

For others that were Google searching this problem and stumble upon this thread like I did...

Try: -Xlint:-deprecation

It seems to work on JDK 6... not sure about others.

Solution 4:

With Java 6, neither the @Depreated annotation, nor a comiler flag will help you here. The only solution that worked for me was to put a javadoc comment with the @deprecated (small caps) tag on the deprecated method:

/**
  * @deprecated overriding deprecated method
  */
@Override
public javax.xml.bind.Validator createValidator() throws JAXBException {...}

(The example is from a class that derives from JAXBContext.)

(I didn't import the deprecated Validator class to avoid a warning on the import statement.)