Short question: Is it possible to create Javadoc for local variables? (I just want an explanation for my local variable when hovering over it in Eclipse) Thanks for any hint
The local variable should be declared a few lines above its usage. Just use regular comments if you need to. But more importantly, keep methods short, choose meaningful names for them, and declare them only when you need them. Most of the time, it's completely unnecessary to comment local variables.
Prefer
int numberOfBooks = books.size();
over
// the number of books
int n;
... // 50 lines of code
n = books.size();
It can be done using Annotations
.
Create a simple annotation type such as the following:
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.LOCAL_VARIABLE)
@interface LocalVariableDocumentation {
String value();
}
And use it on your local variable:
@LocalVariableDocumentation("A very important object!")
Object anImportantObject;
Eclipse will show the annotation in the tooltip.
No, it's not supported because JavaDoc generation will ignore it.
The only way it's possible is with global variables. Local variables cannot be annotated with JavaDoc's.
Yes it's possible. Just make a regular javadoc comment above the variable.
public class ExampleClass {
/** A really cool variable */
int localVariable;
...
Now you can hover above the variable in the code further down and the comment will be shown.
Just make a link to your local variable
String someLocalVariable;
/**
* This a local variable: {@link #someLocalVariable}
*/