A method, class, or variable that should no longer be used is sometimes referenced in too many places or by too many external parties to be removed immediately. The @deprecated keyword can communicate this fact to other developers.

When @deprecated is added to Java code, always say why it has been deprecated and offer an alternative with examples.  

Or, don't add deprecated at all and fix the code immediately before moving on.

/**
 * @deprecated
 */
final String YES = "yes";

In the above example, the users of YES know it has been deprecated, but don't have any clues on what to use instead.  There is a good chance they will create their own version of YES unless offfered an alternative:

/**
 * @deprecated Use SUCCESS or FAILURE definitions instead,  
 *  YES and NO don't mean anything
 */
final String YES = "yes";

Trap: A common mistake is to deprecate code rather than remove it. The consequences of this are that deprecation warnings increase during the project and obscure the real (important) deprecation warnings.

blog comments powered by Disqus