如何在不覆盖方法本身的情况下覆盖方法的 javadoc?
How to override method's javadoc without overriding the method itself?
假设我有两个 classes:
public abstract class AbstractFoo {
/**
* Do bar. Subclasses may override this method, it is not required that they do baz.
*/
public void bar() {
// default implementation
}
}
public class ConcreteFoo extends AbstractFoo {
/**
* Do bar. <b>Note:</b> does not do baz, you have to do it yourself.
*/
@Override
public void bar() {
super.bar();
}
}
在 subclass (ConcreteFoo
) 中我想覆盖 bar()
的 javadoc 但保持在 super class (AbstractFoo
).有没有办法在不覆盖方法的情况下做到这一点?
不,绝对没有办法做到这一点。
但是,您应该使用
/**
* {@inheritDoc}
* add whatever you would like here
*/
作为实现 javadoc 的表示法,如果您打算真正覆盖该方法。
没办法,但是你可以使用 javadoc 的克隆方法:
Creates a new object of the same class as this object. It then initializes each of the new object's fields by assigning it the same value as the corresponding field in this object. No constructor is called.
假设我有两个 classes:
public abstract class AbstractFoo {
/**
* Do bar. Subclasses may override this method, it is not required that they do baz.
*/
public void bar() {
// default implementation
}
}
public class ConcreteFoo extends AbstractFoo {
/**
* Do bar. <b>Note:</b> does not do baz, you have to do it yourself.
*/
@Override
public void bar() {
super.bar();
}
}
在 subclass (ConcreteFoo
) 中我想覆盖 bar()
的 javadoc 但保持在 super class (AbstractFoo
).有没有办法在不覆盖方法的情况下做到这一点?
不,绝对没有办法做到这一点。
但是,您应该使用
/**
* {@inheritDoc}
* add whatever you would like here
*/
作为实现 javadoc 的表示法,如果您打算真正覆盖该方法。
没办法,但是你可以使用 javadoc 的克隆方法:
Creates a new object of the same class as this object. It then initializes each of the new object's fields by assigning it the same value as the corresponding field in this object. No constructor is called.