Dealing with Deprecation Warnings
Problem
Your code used to compile cleanly, but now gives deprecation warnings.
Solution
You must have blinked :-). Either live with the warnings -- live dangerously -- or revise your code to eliminate the warnings.
Discussion
Each new release of Java includes
a lot of powerful new functionality, but
at a price: during the evolution of this new stuff, Java’s
maintainers find some old stuff that wasn’t done right and
shouldn’t be used anymore because they can’t really fix
it. In building JDK 1.1, for example, they realized that the
java.util.Date
class
had some serious limitations with regard to internationalization.
Accordingly, many of the Date class methods and
constructors are marked “deprecated.” To
deprecate something means, according to my
Concise Oxford Dictionary of Current English,
to “express wish against or disapproval of.” Java’s
developers are therefore expressing a wish that you no longer do
things the old way. Try compiling this code:
import java.util.Date;
/** Demonstrate deprecation warning */
public class Deprec {
public static void main(String[] av) {
// Create a Date object for May 5, 1986
// EXPECT DEPRECATION WARNING
Date d = new Date(86, 04, 05); // May 5, 1986
System.out.println("Date is " + d);
}
}What happened? When I compile it on Java 2, I get this warning:
C:\javasrc>javac Deprec.java Note: Deprec.java uses or overrides a deprecated API. Recompile with "-deprecation" for details. 1 warning C:\javasrc>
So, we follow orders. ...