[Fixed] uses or overrides a deprecated api. recompile with -xlint:deprecation for details.

In this post, we will see about warning message uses or overrides a deprecated api. recompile with -xlint:deprecation for details in java.

What is warning message: uses or overrides a deprecated api

You will get this warning when you are using deprecated api in your code.

Example:
Let’s say you have simple swing code which displays a JFrame with JButton on it.

When you will compile the code, you will get below output:

C:\Users\Arpit\Desktop\javaPrograms>javac JFrameDeprecatedAPIExample.java
Note: JFrameDeprecatedAPIExample.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

As you can see, compile gives us warning message that JFrameDeprecatedAPIExample.java uses or overrides a deprecated API.

We are getting this warning message because JFrame’s show() method is deprecated and should not be used.

If you want to know about deprecated API, you can use below command:

C:\Users\Arpit\Desktop\javaPrograms>javac JFrameDeprecatedAPIExample.java -Xlint:deprecation
JFrameDeprecatedAPIExample.java:18: warning: [deprecation] show() in Window has been deprecated
frame.show();
^
1 warning

💡 Did you know?

If you are using IDEs like eclipse or intellij, then it will show deprecated APIs with strike through.

If you are using maven, you can use -Dmaven.compiler.showDeprecation=true with maven goals.

Here is an example:

How to resolve warning message: uses or overrides a deprecated api.

You can resolve this warning message by using recommned API.

In our example, we should use setVisible(true) rather than show() method.

When you will compile above code, you won’t get warning message anymore.

C:\Users\Arpit\Desktop\javaPrograms>javac JFrameDeprecatedAPIExample.java

That’s all about how to fix uses or overrides a deprecated api. recompile with -xlint:deprecation for details in java.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.