java.is.for.desktop
java.is.for.desktop

Reputation: 11216

How can a method's Javadoc be copied into other method's Javadoc?

I know that there is @inheritDoc, but it's only for methods which override others.

I have several classes with many delegate methods (which do not override others).

Can their Javadoc be "inherited" (more exactly: copied)?

/** here I need the copy of wrappedMethod's Javadoc */
public void delegateMethod(Object param){
  innerSomething.wrappedMethod(param);
}

Upvotes: 39

Views: 16024

Answers (3)

apflieger
apflieger

Reputation: 1231

Using @see, you can put a reference to the other method

/** 
 * @see #wrappedMethod(Object)
 */
public void delegateMethod(Object param){
  innerSomething.wrappedMethod(param);
}

Upvotes: 0

DJClayworth
DJClayworth

Reputation: 26846

Sometimes it's actually a good thing to cut and paste documentation. 'Linking' documentation in some way, especially when there isn't in inheritance relationship, runs the risk that one of the methods will have it's behaviour changed somehow, making the linked documentation no longer valid.

However in the case of delegates I've had the same problem a number of times. Usually you have a public method on a main class delegating to a package-private delegate, which has exactly the same behaviour as the main method. Here the solution is simple - document the main class, and put the @link or @see on the delegate class. Everybody can see the main class' documentation. You will probably need to have more detailed documentation, such as implementation details, on the delegate class too.

Upvotes: 11

Danny Thomas
Danny Thomas

Reputation: 2199

A @link or @see tag would be appropriate here. If you're wrapping the method, it must provide distinctive behavior which makes it unsuitable for overloading or otherwise.

Upvotes: 19

Related Questions