且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javadoc 从类中排除一些公共方法

更新时间:2023-09-17 14:27:22

我假设您要从 javadoc 中排除的方法是您不希望客户端使用的公共方法.换句话说,这些方法已弃用.您需要做的是使用@Deprecated 注释.像这样:

I assume the methods you want to exclude from javadoc are public methods that you don't want your client to use. In other words, these methods are deprecated. What you need to do is using the @Deprecated annotation. Like this:

@Deprecated public void badMethod() {
    ...
}

现在,badMethod() 已被弃用.如果有人在他的代码中使用了 badMethod(),他会收到来自编译器的警告(他使用的是不推荐使用的方法).

Now, the badMethod() is deprecated. If someone uses badMethod() in his code, he'll get a warning from the compiler (that he's using a deprecated method).

但是,@Deprecated 注释不排除 javadoc 中已弃用的方法.为了从 javadoc 中排除该方法,您需要执行以下操作:生成 javadoc 时,请使用 nodeprecated javadoc cmd 行选项.-nodeprecated 选项可防止在文档中生成任何已弃用的 API.因此,如果您使用 @Deprecated 批注并使用 -nodeprecated 选项生成 javadoc,那么您的错误方法将不会出现在 javadoc 中.

However, the @Deprecated annotation doesn't exclude the deprecated method from javadoc. Here's what you need to do in order to exclude the method from javadoc: When you generate javadoc, use the nodeprecated javadoc cmd line option. The -nodeprecated option prevents the generation of any deprecated API in the documentation. So if you use the @Deprecated annotation and generate javadoc with the -nodeprecated option, your bad method won't appear in the javadoc.

但在我看来,您不应该从您的 javadoc 中排除已弃用的公共方法.如果它们出现在文档中并解释为什么不推荐使用该方法以及使用什么来代替,那就更好了.

But in my opinion, you shouldn't exclude deprecated public methods from your javadoc. It's better if they appear in the documentation with an explanation of why the method is deprecated and what to use instead.