Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress javac warnings about deprecated api?

When I compile, javac outputs:

Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details.` 

I wish to suppress this warning. Trying -Xlint:none does not seem to help.

like image 506
IttayD Avatar asked Oct 12 '09 13:10

IttayD


People also ask

How do you stop a deprecated warning?

Place the @SuppressWarnings annotation at the declaration of the class, method, field, or local variable that uses a deprecated API. The @SuppressWarnings options are: @SuppressWarnings("deprecation") — Suppresses only the ordinary deprecation warnings.

What are deprecated warnings?

Deprecation warnings are a common thing in our industry. They are warnings that notify us that a specific feature (e.g. a method) will be removed soon (usually in the next minor or major version) and should be replaced with something else.

What is deprecated API in Java?

A deprecated API is one that you are no longer recommended to use, due to changes in the API. While deprecated classes, methods, and fields are still implemented, they may be removed in future implementations, so you should not use them in new code, and if possible rewrite old code not to use them.


2 Answers

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.

like image 132
Thomas Owens Avatar answered Oct 06 '22 16:10

Thomas Owens


Two possible ways:

  1. don't use deprecated API
  2. Use @SuppressWarnings("deprecation")
like image 39
Joachim Sauer Avatar answered Oct 06 '22 16:10

Joachim Sauer