可以利用 {@inheritDoc} 讓子類別可以繼承父類別的文件,可以參閱 [1]。
不過如果遇到要覆寫的對象是 constructor 時
因為 constructor 不需要也不允許寫 @override,會導致無法利用 {@inheritDoc} 來繼承父類別的文件
這時的作法可以利用 @see 來加上間接的註解 [2]
雖然沒辦法像 {@inheritDoc} 那樣直接連結到父類別,但總算是點一下連結還是看得到。
以下範例轉載自 [2] 當中網友 My-Name-Is 的回應:
public class TestReflectionHelper extends TestReflectionHelperCommon {
/**
* @see TestReflectionHelperCommon#TestReflectionHelperCommon()
*/
public TestReflectionHelper() {
super();
}
/**
* @see TestReflectionHelperCommon#TestReflectionHelperCommon(Class, String,
* Class...)
*/
public TestReflectionHelper(final Class<?> targetClass,
final String targetMethod, final Class<?>... parameterTypes) {
super(targetClass, targetMethod, parameterTypes);
}
...
}
參考資料:
1、Javadoc: inheritDoc
2、Why is inheritedDoc not defined on constructors?
沒有留言:
張貼留言