Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactorable reference to a method parameter in javadoc

How do I make a reference, in javadoc, to a method parameter, so that the reference can be refactored ?
For example:

public class A {

    private int field;

    /**
     * @param p 
     * {@link #field} is initialized using the value of p.
     */
    void foo(int p)
    {
        //...

    }
}       

If I rename parameter p in the above code, I want

"...using the value of p"

text to change accordingly (just as renaming field will change {@link #field} ).
I read this old post, and some more sources, but could not find a way to do it.
Does javadoc support it ?

like image 402
c0der Avatar asked Jul 13 '16 08:07

c0der


1 Answers

Due to Java erasure, method argument names are ephemeral, they are not part of the static class definition. So, void foo(int p) being changed to void foo(int x) is not considered refactoring, because it is guaranteed that it will not affect the program's logic in any way (unless the argument is overloading a class field).

So in the javadoc there cannot be a static link that identifies the method argument. The mere fact that the word after @param changes when you refactor the method is a favor offered by the IDE.

like image 159
Deroude Avatar answered Sep 18 '22 01:09

Deroude