Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with JavaDoc comment repetition?

I was wondering what the best way of documenting this potential Point class is:

public class Point {
    /* the X coordinate of this point */
    private int x;
    /* the Y coordinate of this point */
    private int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }
}

My concrete concern lies with the repetition between the x and y attributes and their respective getters and setters, as well with the constructor arguments.

It's not that I'm developing a public API or anything of the likes, it's no problem for me to have a general comment regarding some variable and then having the getter and setter have just the same text, for instance. I'd just like to avoid comment repetition in my own internal code. Is there a way to tie getX() and the int x argument of the constructor to the x attribute, for instance?

Thanks

like image 272
devoured elysium Avatar asked Nov 12 '22 12:11

devoured elysium


1 Answers

Is there a way to tie getX() and the int x argument of the constructor to the x attribute, for instance?

No, not that I'm aware of. What I do:

  • don't comment getters (or setters) at all
  • if X needs contextual information and if it somehow represents (part of the) state of the class I document it in the class-level Javadoc only
like image 66
Marcel Stör Avatar answered Nov 15 '22 05:11

Marcel Stör