Java代码中的注释
时间:2020-02-23 14:36:10 来源:igfitidea点击:
注释是代码的重要组成部分。
如果我们编写好的注释,其他人可以更容易理解代码。
编译器编译程序时,编译器会忽略注释。
Java代码中有三种类型的注释。
- 单行注释
- 多行注释
- Java Doc注释
单行注释:
这些是最常用的Java注释。
它用于注释单行。
//This is single line comment
例如:
public class CommentsExample {
int count; //Here count is a variable
}
多行注释:
如果要在多行写入注释,则单行注释可能会乏味写入。
在这种情况下,我们可以使用多行注释。
/* This is multi line comment * * */
例如:
public class CommentsExample {
/* Count is a variable which is used
* to count number of incoming requests
*/
int count;
}
javadoc注释:
如果要为类生成Javadoc,则可以使用Javadoc注释。
运行javadoc命令时,它会自动使用javadoc注释生成javadoc
/** This is javadoc comment * * */
例如:
public class CommentsExample {
/**
* This method is used to find sum of two integers
* @param a
* @param b
* @return
*/
public int sum(int a,int b)
{
int c=a+b;
return c;
}
}
注释是代码的最重要部分。
我们应该在需要时使用它们。

