How Exactly Does @param Work - Java

前端 未结 5 982
猫巷女王i
猫巷女王i 2020-12-05 09:50

How does the annotation @param work?

If I had something like this:

/* 
*@param testNumber;
*/

int testNumber = 5;
if (testNumber < 6         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 10:33

    @param will not affect testNumber.It is a Javadoc comment - i.e used for generating documentation . You can put a Javadoc comment immediately before a class, field, method, constructor, or interface such as @param, @return . Generally begins with '@' and must be the first thing on the line.

    The Advantage of using @param is :- By creating simple Java classes that contain attributes and some custom Javadoc tags, you allow those classes to serve as a simple metadata description for code generation.

        /* 
           *@param testNumber
           *@return integer
        */
        public int main testNumberIsValid(int testNumber){
    
           if (testNumber < 6) {
              //Something
            }
         }
    

    Whenever in your code if you reuse testNumberIsValid method, IDE will show you the parameters the method accepts and return type of the method.

提交回复
热议问题