javadoc @hide 无法工作

javadoc @hide can't work

根据link,我写了如下代码:

/**
 * @hide
 * */
public void myMethod() {
    // do something
}

当我使用命令生成文档时:

$ javadoc -locale en_US -encoding UTF-8 -charset UTF-8 -d doc xxx.java

文档还有 myMethod 项。那么如何隐藏myMethod呢?我错过了什么?

您正在使用 Doclava 标记,但正在使用标准 doclet 生成 API 文档。

Building Doclava

The Doclava source comes bundled with an ant script to build the doclet. The "jar" task will build a jar containing Doclava and all necessary dependencies.

Using Doclava with Javadoc

The command line arguments to pass to Javadoc to use Doclava are: -doclet com.google.doclava.Doclava -docletpath ${jar.file}

根据官方 Javadoc FAQ,目前无法直接隐藏 public 成员。

Occasionally you might need to make a class or method public so that it can be accessible from other packages, not because you want it to be part of the public API. Having these methods appear in the documentation merely confuses application developers.

There is currently no Javadoc option to hide, exclude or suppress public members from the javadoc-generated documentation.

Several options are available:

  • Excluding source files - You can pass into javadoc only the source filenames for all classes you want to document, and exclude those you want to omit. Notice this has the granularity of files, not classes. Therefore, if you exclude a source file that contains nested classes, they would also be excluded. (You can put the list of classes in a command line argument file rather than directly on the command line.) The default Javadoc offers no way to omit classes when passing in package names on the command line.
  • Excluding individual classes - You can use the Exclude Doclet. This has finer granularity (class rather than source file) than the previous option, and would be more natural to use because you explicitly list in a file the files you want to exclude.
  • Excluding classes, methods and fields - The yDoc Doclet has this capability, where you mark items with an exclusion tag in the source code. In addition, anyone is welcome to extend the Exclude Doclet above for methods and fields -- we'd be happy to publish it and add your name to the credits.

We are considering @exclude as a proposed tag for excluding members.

另请查看 Proposed Javadoc Tags page 了解有关 @exclude@hide 的更多信息。

使用下面的 @hidden 标签,它是 introduced in JDK 9 并且也适用于 JDK 17。

class Test {
 /**
  * This is hidden
  * @hidden
  *
  * @param a
  * @param b
  */
 public int add(int a, int b) {
     return a + b;
 }
}

此标签可以隐藏 java API、变量、构造函数等的文档

命令生成java文档:
javadoc Test.java