Java supports two mechanisms for deprecation: and an annotation, (supported starting with J2SE 5.0) and a Javadoc tag (supported since 1.1). Existing calls to the old API continue to work, but the annotation causes the compiler to issue a warning when it finds references to deprecated program elements.
The @SuppressWarnings annotation disables certain compiler warnings. In this case, the warning about deprecated code ( "deprecation" ) and unused local variables or unused private methods ( "unused" ).
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.
To avoid the warning: do not import the class
instead use the fully qualified class name
and use it in as few locations as possible.
Use this annotation on your class or method:
@SuppressWarnings( "deprecation" )
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.
I solved this by changing the import to:
import package.*
then annotating the method that used the deprecated classes with@SuppressWarnings("deprecation")
Suppose that you are overriding/implementing an interface with a deprecated method (such as the getUnicodeStream(String columnLabel)
in java.sql.ResultSet
) then you will not get rid of deprecation warnings just by using the annotation @SuppressWarnings( "deprecation" )
, unless you also annotate the same new method with the @Deprecated
annotation. This is logical, because otherwise you could undeprecate a method by just overriding its interface description.
you can use:
javac FileName.java -Xlint:-deprecation
But then this will give you warnings and also tell you the part of the code that is causing deprecation or using deprecated API. Now either you can run your code with these warnings or make appropriate changes in the code.
In my case I was using someListItem.addItem("red color")
whereas the compiler wanted me to use someListItem.add("red color");
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With