Java Reference
In-Depth Information
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 the first major revision, for
example, they realized that the
java.util.Date
class had some serious limitations with re-
gard to internationalization. Accordingly, many of the
Date
class methods and constructors
are marked “deprecated.” According to the
American Heritage Dictionary
, to deprecate
something means to “express disapproval of; deplore.” Java's developers are therefore disap-
proving of the old way of doing things. Try compiling this code:
import
import
java.util.Date
java.util.Date
;
/** Demonstrate deprecation warning */
public
public class
class
Deprec
Deprec
{
public
public static
static
void
void
main
(
String
[]
av
) {
// Create a Date object for May 5, 1986
Date d
=
new
new
Date
(
86
,
04
,
05
);
// EXPECT DEPRECATION WARNING
System
.
out
.
println
(
"Date is "
+
d
);
}
}
What happened? When I compile it, 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. For details, recompile with
-deprecation
(if using Ant, use
<javac
deprecation=
true
…>
):
C:\javasrc>
javac -deprecation Deprec.java
Deprec.java:10: warning: constructor Date(int,int,int) in class java.util.Date
has been deprecated
Date d = new Date(86, 04, 05); // May 5, 1986