views:

56

answers:

2

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);
}
+2  A: 

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.

Danny Thomas
Yes, but `@link` or `@see` are sadly not useful when the wrapped method is protected :(
java.is.for.desktop
unless you generate javadocs for protected methods also...
seanizer
`@seanizer` Oh, I didn't know that it is possible, thank you!
java.is.for.desktop
A: 

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.

DJClayworth