Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javadoc for local variables?

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 :-)

like image 892
stefan.at.wpf Avatar asked May 12 '12 18:05

stefan.at.wpf


People also ask

How do you comment variables in Javadoc?

Writing Javadoc Comments In general, Javadoc comments are any multi-line comments (" /** ... */ ") that are placed before class, field, or method declarations. They must begin with a slash and two stars, and they can include special tags to describe characteristics like method parameters or return values.

How do you declare a local variable in Java?

Local variables are declared in methods, constructors, or blocks. Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block. Access modifiers cannot be used for local variables.

Do you write Javadoc for private methods?

Nope, you shouldn't write javadoc for private methods. End users don't have access to private fields or methods so there really isn't a point in providing javadoc for them. Private fields and methods are only meant for the developer. If you really need to though, feel free to write comments for non-obvious logic.

Can we use access modifiers for local variables?

Yes, a local variable can be public, private, protected or default.


2 Answers

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.

like image 61
Elist Avatar answered Oct 02 '22 14:10

Elist


No, it's not supported because JavaDoc generation will ignore it.

like image 41
nitind Avatar answered Oct 02 '22 14:10

nitind