tags:

views:

324

answers:

3

I've been looking through the javadoc documentation on Sun's site, trying to find if there's a javadoc tag which can be used to document a class or method's generic type signature.

Something like @typeparam, similar to the usual @param, but applicable to types as well as methods,e.g.

/**
 *  @typeparam T This describes my type parameter
 */
class MyClass<T> {
}

I suspect there is no such tag - I can find no mention of it anywhere, and the JavaSE API docs don't show any sign of it, but it seems like an odd omission. Can someone put me right?

+6  A: 

It should be done just like this:

/**
 * @param <T> This describes my type parameter
 */
class MyClass<T>{

}

Source

Timo Willemsen
Doh.... OK, that's embarrassingly obvious... it does beg the question as to why the JavaSE classes (e.g. `Collection`) don't use it, though.
skaffman
Strange this is, it's not documented in the standard documentation.
Timo Willemsen
LinkedList uses it: http://java.sun.com/j2se/1.5.0/docs/api/java/util/LinkedList.html
Timo Willemsen
+2  A: 

Yes. Just use the @param tag, and include angle brackets around the type parameter.

Like this:

/**
 *  @param<T> This describes my type parameter
 */
A: 

I don't think this omission is odd. By virtue of being a generic type (erased at runtime), the type parameter is really not part of the api.

If you are concerned about the essence of the type itself and want to document it, perhaps you need to restrict it (e.g. MyClass <T extends MyType>)?

Yoni
I disagree strongly. If I'm using an API class with a type parameter, I need to know what that type parameter means. It *does* have to be documented.
skaffman
-1: There is no omission. Moreover, that type parameters are erased (simplistically speaking) at runtime is irrelevant, because javadoc is not used at runtime.
meriton