我有一个旧类,我已使用 @Deprecated
注释将其弃用。同时,我创建了另一个类来替换那个已弃用的类。
在那个新类的 Javadoc 中,我已经提到它旨在替换已弃用的类。这会导致导入已弃用的类,并给了我已弃用的警告。要删除警告,我必须使用 @SuppressWarnings("deprecation")
注释。结果是我的新类看起来像是在使用已弃用的内容。
例子:
/**
* Deprecated class.
* @deprecated Replaced by @{link ReplacingClass}
*/
@Deprecated
public class DeprecatedClass {}
替换类:
import com.test.example.DeprecatedClass;
/**
* This class replaces the deprecated class @{link DeprecatedClass}
*/
@SuppressWarnings("deprecation")
public class ReplacingClass {}
我能做些什么来防止这种情况发生?
最佳答案
您不必导入类以在 Javadoc 中引用它。您有两种选择来引用类。您可以使用完全限定的类名,或者如果类在搜索空间中,则可以使用简单的类名:
- the current class or interface
- any enclosing classes and interfaces, searching closest first
- any superclasses and superinterfaces, searching closest first
- the current package
- any imported packages, classes and interfaces, searching in the order of the import statement
在您的情况下,导入 (5) 会导致弃用警告,因此您可以只使用已弃用类的完全限定类名:
/**
* This class replaces the deprecated class @{link com.test.example.DeprecatedClass}
*/
public class ReplacingClass {}
或者如果这两个类在同一个包中,你只需要删除import
语句。
关于java - 由于 Javadoc,避免在替换类中抑制 "deprecated",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44014346/