views:

126

answers:

4

I've searched through the web and what I've found out is this:

To make the compiler warn you of the details of which methods you used that were deprecated use the javac.exe -deprecation switch. Then look in the Javadoc for the deprecated methods to find out the recommended replacements. Sometimes you just have to rename. Sometimes the replacements work quite differently.

But I'm not really understand how it works, can anybody help me with this?

A: 

You can use any IDE like eclipse which has a option of showing the deprecated methods while programming if you have attached the required javadoc for the classes which you are using.

GK
+3  A: 

Method deprecation is done to warn programmers that the method is not currently the best one to use for the functionality that's desired. It's done by using the @deprecated javadoc annotation. When you use the -deprecated flag to javac, it's just telling javac to raise a warning when it sees these javadoc annotations. It tells you the line number where you used the deprecated method, and the name of the deprecated method.

From there, it's up to you to look at the JDK's javadoc on Sun's (er...Oracle's) site to see what the recommendations are for getting the functionality you desire. Sometimes the replacement involves making multiple method calls, where you would have made just one in the past. Usually the documentation is good about giving you examples, and pointing you in the right direction when there's a new way of doing things.

Rob Heiser
thanks! I will try it to find my problem.. =)
keitamike
+2  A: 

To find identify the deprecated methods and classes, you do what the quoted text says. You compile with the "-deprecation" switch and the offending methods/classes will be shown as compilation warning messages. (If you are using an IDE, then the deprecation warnings will be enabled / disabled some other way.)

If you are actually asking how the compiler knows that a method or class is deprecated, the answer is that a class or method is marked as deprecated by putting a "@deprecated" tag into the corresponding javadoc comment. The java compiler notes this, and sets an attribute in the bytecode file when it compiles the class. Then, when you try to use the class/method in your code, the java compiler reads the bytecodes, notes the attribute and outputs the warning message.

Deprecation is intended as a strong hint to the developer that the method or class in question should no longer be used. A deprecated class or method typically has some flaw in it (major or minor) that could not be fixed without breaking existing code. Rather, a non-compatible replacement has been implemented that requires you to make some changes to your source code.

In theory, deprecated classes and methods may be removed in future releases. While Sun rarely (if ever) does this, third-party library developers are more willing to remove deprecated methods when cleaning up their APIs.

Stephen C
thanks for your explaination. I think i get what does it means! :)
keitamike
A: 

You can use NetBeans IDE. It will show the deprecated methods by strike that method and also you can view the reason and alternative methods for that.

Samurai