You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Javadoc生成时子类未显示问题及树形结构生成需求

问题

我尝试为一个继承其他类的抽象类生成Javadoc,但生成的Javadoc树形结构里看不到子类。我用IntelliJ IDEA操作,通过终端执行src>javadoc GraphicObject.java命令生成Javadoc。

期望的树形结构:

- GraphicObject
  - Rectangle 

但实际只显示父类GraphicObject。相关代码如下:

/**
*
*
*/
public abstract class GraphicObject {
/*\*
* The x-coordinate of the graphic object.
*/
protected int x;
/*\*
* The y-coordinate of the graphic object.
*/
protected int y;
/*\*
* The width of the graphic object.
*/
protected int width;
/*\*
* The height of the graphic object.
*/
protected int height;
/*\*
* Constructs a new graphic object with the specified coordinates, width, and
* height.
*
* @param x the x-coordinate
* @param y the y-coordinate
* @param width the width
* @param height the height
*/
public GraphicObject(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
/*\*
* Moves the graphic object to the specified coordinates.
*
* @param x the new x-coordinate
* @param y the new y-coordinate
*/
public abstract void move(int x, int y);

}
/**

* This is a subclass of GraphicObject that represents a rectangle.
*
*
* @see GraphicObject "This class extends GraphicObject."
  */
  class Rectangle extends GraphicObject {
  public Rectangle(int x, int y, int width, int height) {
  super(x, y, width, height);
  }
  @Override
  public void move(int x, int y) {
  this.x = x;
  this.y = y;
  }
  }

解决方案

1. 命令行需包含子类文件

你只指定了GraphicObject.java作为生成目标,Javadoc工具只会处理这个文件,不会自动扫描同目录下的子类。把子类文件也加入命令:

src>javadoc GraphicObject.java Rectangle.java

如果类数量多,也可以用通配符批量处理:

src>javadoc *.java

2. 修改子类的访问修饰符

你的Rectangle类没有访问修饰符,默认是包私有。Javadoc默认只生成public/protected类的文档,包私有类不会被纳入。把Rectangle改成public:

public class Rectangle extends GraphicObject {
    public Rectangle(int x, int y, int width, int height) {
        super(x, y, width, height);
    }
    @Override
    public void move(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

3. 修正Javadoc注释格式

代码里成员变量和方法的注释用了/*\*,正确的应该是/**(多余的反斜杠会导致Javadoc无法识别注释),修正后示例:

/**
 * The x-coordinate of the graphic object.
 */
protected int x;

内容的提问来源于stack exchange,提问作者yukthi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 23:45:19