Reputation: 31
I have a class (for example) "OverridenArrayList". Which overrides a few methods of a normal ArrayList. Now I want to generate a Javadoc which should contains the methods I changed of course and a few other important methods which are NOT overridden (And also not generated in the exported JavaDoc). For example the "size()" method.
Of course I could override the method like this
@Override
public int size() {
return super.size();
}
And it would be generated too. But this would be sometimes a bit annoying if there are more than e.g. 10 important methods and I have to write these 10 methods in every subclass I create.
It would be nice if someone could tell me another easier way to tell Eclispe that it should generate these "important" methods to all subclasses, too.
Upvotes: 0
Views: 1744
Reputation: 4695
You need to use the {@inheritDoc}
tag.
Do not forget to use -sourcepath
and have the sources available. In this case, you want to copy the Javadoc comments from a JDK library class. This means you need to have JDK sources (src.zip) downloaded and exploded somewhere. I am not sure how to do this on Eclipse, but if you were to do this on command line, you'd do:
ArrayList
, say FooList.java
.javadoc -sourcepath jdk-sources -d doc FooList.java
.Here's an example:
public class FooList<T> extends ArrayList<T> {
/** This method is a new method, so javadoc should be visible */
public void newMethod() {
}
/** Javadoc is overloaded, since I rewrote the javadoc comments*/
@Override
public int size() {
return super.size();
}
/** <p>
* This is an overloaded method, so javadoc should be visible
* </p>
* {@inheritDoc}
* @return
* {@inheritDoc}
* */
@Override
public T get(int index) {
System.out.println(" foo ....");
return super.get(index);
}
}
In Intellij, I see the Javadoc for the get
method (on ^J) as follows:
Note the use of {@inheritDoc}
in both main body and @return
.
Upvotes: 0
Reputation: 10964
I don't think what you are trying to accomplish is possible. How should JavaDoc know the methods that you want to include in your documentation? However by default there will be a list in your class' JavaDoc with all inherited methods.
To give the user of your class some hints on methods that you consider to be important, you may of course use the @see
or @link
JavaDoc tags to create links to the documentation of the inherited methods.
Upvotes: 1
Reputation: 915
JavaDoc will be generated regardless of method is overriden or not. You need to have the proper comment format for the methods where you need the javadoc to generate it.
Refer below: http://www.tutorialspoint.com/java/java_documentation.htm
Add thie above your methods to get JavaDoc:
/** documentation */
Hope i understood your question correctly :)
Upvotes: 0