Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic propagation of private field javadoc's to getters/setters?

I've documented my bean private fields with Javadoc, explaining what each field is for. Can i propagate these documentations somehow to corrseponding getters/setters to reduce duplications of documentation? Is there's some kind of Javadoc macro for this at least?

like image 550
NagyI Avatar asked Jul 13 '11 10:07

NagyI


People also ask

How do you generate javadocs for getters and setters?

Open a Java source code with the Java Editor of Eclipse and move the cursor inside the class definition (an inner class can be selected). Select "Javadoc -> Generate Getter/Setter Javadocs from Field Javadocs..." in the main menu of Eclipse or the context menu of the editor, and a dialog opens.

Can getters and setters be private?

The reason for declaring the getters and setters private is to make the corresponding part of the object's abstract state (i.e. the values) private. That's largely independent of the decision to use getters and setters or not to hide the implementation types, prevent direct access, etc.

How do you use Lombok to create getters and setters?

You can annotate any field with @Getter and/or @Setter , to let lombok generate the default getter/setter automatically. A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field's type is boolean ).


1 Answers

You could link the javadoc comment of getters and setters to the private field by adding a javadoc link:

{@link Class#field}

However i would not really recommend this. As the previous commentators stated, i would just document the getters and setters properly. Javadoc documents your public API, which the getters and setters may belong to. Your private fields do not belong to the public API.

like image 80
GeorgeG Avatar answered Sep 19 '22 15:09

GeorgeG