什么是已弃用的注释目标 - 实现、接口或两者?

What is a deprecated annotation target - implementation, interface or both?

你好,我想知道我是否必须在所有出现的不推荐方法上注释,如接口、基础(抽象 Class)和所有实现 Classes 或者是接口中的一个注释够了吗?

实际上取决于弃用 类 的使用方式。如果您使用 良好实践(实例化接口以使用实现),则弃用接口(方法或属性)就足够了。

无论如何,

  • 您不能确保/强制其他用户执行此操作
  • 并非所有 compilers/parsers 都会抛出警告或显示 javadoc @deprecated 标记

    Using the @Deprecated annotation to deprecate a class, method, or field ensures that all compilers will issue warnings when code uses that program element. In contrast, there is no guarantee that all compilers will always issue warnings based on the @deprecated Javadoc tag, though the Sun compilers currently do so. Other compilers may not issue such warnings. Thus, using the @Deprecated annotation to generate warnings is more portable that relying on the @deprecated Javadoc tag.


正在恢复:如果要弃用方法实现,则必须同时弃用接口和实现。

来源1 2 3