Deprecation Warnings


The above code will compile and pass the tests, but you will see a warning or note in the compilation output. If you are using an IDE, you might not see the warnings. Find out how to turn on the warningsyou don't want to hide them.

Eliminate all warnings.


Ignoring a compiler warning is like ignoring a sore toothyou'll pay for it sooner or later, and it may end up costing you dearly to ignore it for too long.[7]

[7] He writes, as he sits here with a corrupt molar . . .

 Note: CourseSessionTest.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 

If you are compiling from the command line, you should do just what the message says: Enter the compilation command again, but modify it to include the compilation switch -Xlint:deprecation option.

 javac -classpath c:\junit3.8.1\junit.jar -Xlint:deprecation *.java 

The new compile output should look something like this:

 CourseSessionTest.java:15: warning: Date(int,int,int) in java.util.Date has been deprecated         startDate = new Date(year, month, date);                ^ CourseSessionTest.java:43: warning: Date(int,int,int) in java.util.Date has been deprecated         Date sixteenWeeksOut = new Date(year, month, date);                      ^ 2 warnings 

If you are running in an IDE, it will have a setting somewhere to allow you to turn warnings on or off. You might already have seen similar deprecation messages, since warnings are usually "on" by default. In any case, the warnings should be disturbing to your craftsperson sensibilities. May they nag at you incessantly. You will soon learn a different way to construct dates that does not result in the warnings.

The test should run just fine. But you have lots of little ugliness in the code that can be cleaned up.



Agile Java. Crafting Code with Test-Driven Development
Agile Javaв„ў: Crafting Code with Test-Driven Development
ISBN: 0131482394
EAN: 2147483647
Year: 2003
Pages: 391
Authors: Jeff Langr

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net