Code is sometimes annotated as deprecated by developers maintaining libraries or APIs to indicate that the method, class, or other programming
element is no longer recommended for use. This is typically due to the introduction of a newer or more effective alternative. For example, when a
better solution has been identified, or when the existing code presents potential errors or security risks.
Deprecation is a good practice because it helps to phase out obsolete code in a controlled manner, without breaking existing software that may
still depend on it. It is a way to warn other developers not to use the deprecated element in new code, and to replace it in existing code when
possible.
Deprecated classes, interfaces, and their members should not be used, inherited or extended because they will eventually be removed. The
deprecation period allows you to make a smooth transition away from the aging, soon-to-be-retired technology.
Check the documentation or the deprecation message to understand why the code was deprecated and what the recommended alternative is.
@Deprecated("This function is deprecated, use newFunction instead", ReplaceWith("newFunction()"))
void oldFunction() {
println("This is the old function.");
}
void newFunction() {
println("This is the new function.");
}
oldFunction() // Noncompliant: "oldFunction is deprecated"
Exceptions
The rule does not raise an issue when the deprecated members are used in a deprecated type.