How to identify obsolete methods in a program?

I searched on the Internet, and here is what I found out:

To let the compiler warn you about which methods you used were deprecated, use javac.exe -deprecation . Then look in Javadoc for obsolete methods to find out recommended replacements. Sometimes you just need to rename. Sometimes substitutions work quite differently.

But I don’t quite understand how this works, can anyone help me with this?

+4
source share
4 answers

Method rejection is performed to warn programmers that the method is currently not the best to use for the desired functions. This is done using the @deprecated javadoc annotation. When you use the -deprecated flag in javac , it just tells javac to raise a warning when it sees these javadoc annotations. It indicates the line number in which you used the deprecated method and the name of the deprecated method.

From there, you need to look at Javkoc on the Sun website (er ... Oracle) to find out what recommendations are for getting the desired functionality. Sometimes a replacement involves making multiple method calls where you would have made only one in the past. Usually the documentation is good at giving you examples and pointing you in the right direction when there is a new way to do something.

+5
source

To find outdated methods and classes, you do what the quoted text says. You compile with the "-deprecation" switch, and the insult methods / classes will appear as warning compilation messages. (If you are using the IDE, deprecation alerts will be activated / deactivated in some other way.)

If you really ask how the compiler knows that the method or class is deprecated, the answer is that the class or method is deprecated by putting the "@deprecated" tag in the corresponding javadoc comment. The java compiler notes this and sets the attribute in the bytecode file when compiling the class. Then, when you try to use the class / method in your code, the java compiler reads the bytecodes, marks the attribute, and displays a warning message.

Obsolescence is intended as a strong hint to the developer that this method or class should no longer be used. An obsolete class or method usually has some flaws in it (primary or secondary) that cannot be fixed without breaking existing code. Instead, an incompatible replacement has been implemented that requires some changes to the source code.

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

+3
source

You can use any IDE, such as eclipse, which can display deprecated methods during programming if you have bound the necessary javadoc for the classes you use.

0
source

You can use the NetBeans environment. It will show deprecated methods by deleting this method, and you can also see the reason and alternative methods for this.

0
source

Source: https://habr.com/ru/post/1306090/


All Articles