【发布时间】:2015-02-15 14:24:48
【问题描述】:
我正在用 java 编写一个接口,我想知道是否应该在接口的方法的 javadoc cmets(@param、@return 等)中包含标签,或者我是否应该只在实现类中包含这些标签'方法的 javadoc cmets。这是一个例子:
我有一个ShapeInterface接口,并且有形状的实现类(圆形、三角形等)
那么javadoc cmets应该是这样的吗?
public interface ShapeInterface{
/**
* Sets the x-coordinate for this shape
* @param x the x-coordinate for this shape
*/
public void setX(int x);
/**
* Gets the x-coordinate of this shape
* @return this.x the x-coordinate of this shape
*/
public int getX();
}
或者它们应该如下所示,标签只出现在实现类方法的 javadoc cmets 中?
public interface ShapeInterface{
/**
* Sets the x-coordinate for this shape
*/
public void setX(int x);
/**
* Gets the x-coordinate of this shape
*
public int getX();
}
谢谢
【问题讨论】:
-
顺便说一句,如果
getX()和setX()应该对 all 形状类型执行完全相同的操作,那么您可能需要考虑从抽象类继承而不是继承创建一个界面。或者,如果使用 Java 8,请将它们设为默认方法 (docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html)
标签: java interface comments javadoc