【JAVA】java做注释,
【JAVA】java做注释,
在写《第一行代码》第二章ActivityTest项目中, 写到在SecondActivity中构造Intent跳转函数
public static void actionStart(Context context, String param1, String param2) {
Intent intent = new Intent(context, SecondActivity.class);
intent.putExtra("param1", param1);
intent.putExtra("param2", param2);
context.startActivity(intent);
}
这个函数是为了在其他Activity跳转到SecondActivity时,能够直接调用该函数,直接了解调用参数。
写完以后,我想的是在其他Activity调用该函数,虽然能够看到参数个数,名字,但是缺少文档解释还是不是很了解每个参数的含义,所以我想用javadoc,但是不知道javadoc的用法,最后查阅的使用结果如下:
/**
* The actionStart method of the SecondActivity.
* This method is called when an Activity wants to skip to SecondActivty.
*
* @param context
* The start Activity of intent
* @param param1
* username
* @param param2
* password
* @throws ServletException
* if an error occurred
*/
public static void actionStart(Context context, String param1, String param2) {
Intent intent = new Intent(context, SecondActivity.class);
intent.putExtra("param1", param1);
intent.putExtra("param2", param2);
context.startActivity(intent);
}
在其他Activity调用该方法的情况如下:
完成。
大家可以参看。
然后我突然想了解下java注释的一些注释规范:
查阅如下:转自: http://blog.csdn.net/shiyuezhong/article/details/8205281
注释原则
1、基本注释(必须加)
(a) 类(接口)的注释
(b) 构造函数的注释
(c) 方法的注释
(d) 全局变量的注释
(e) 字段/属性的注释
备注:简单的代码做简单注释,注释内容不大于10个字即可,另外,持久化对象或VO对象的getter、setter方法不需加注释。具体的注释格式请参考下面举例。
2、特殊必加注释(必须加)
(a) 典型算法必须有注释。
(b) 在代码不明晰处必须有注释。
(c) 在代码修改处加上修改标识的注释。
(d) 在循环和逻辑分支组成的代码中加注释。
(e) 为他人提供的接口必须加详细注释。
备注:此类注释格式暂无举例。具体的注释格式自行定义,要求注释内容准确简洁。
注释格式:
1、单行(single-line)注释:“//……”
2、块(block)注释:“/*……*/”
3、文档注释:“/**……*/”
4、javadoc 注释标签语法
@author 对类的说明 标明开发该类模块的作者
@version 对类的说明 标明该类模块的版本
@see 对类、属性、方法的说明 参考转向,也就是相关主题
@param 对方法的说明 对方法中某参数的说明
@return 对方法的说明 对方法返回值的说明
@exception 对方法的说明 对方法可能抛出的异常进行说明
参考举例
1. 类(接口)注释
例如:
/**
* 类的描述
* @author Administrator
* @Time 2012-11-2014:49:01
*
*/
public classTest extends Button {
……
}
2. 构造方法注释
例如:
public class Test extends Button {
/**
* 构造方法 的描述
* @param name
* 按钮的上显示的文字
*/
public Test(String name){
……
}
}
3. 方法注释
例如
public class Test extends Button {
/**
* 为按钮添加颜色
*@param color
按钮的颜色
*@return
*@exception (方法有异常的话加)
* @author Administrator
* @Time2012-11-20 15:02:29
*/
public voidaddColor(String color){
……
}
}
4. 全局变量注释
例如:
public final class String
implements java.io.Serializable, Comparable<String>,CharSequence
{
/** The value is used for characterstorage. */
private final char value[];
/** The offset is the first index of thestorage that is used. */
private final int offset;
/** The count is the number of charactersin the String. */
private final int count;
/** Cache the hash code for the string */
private int hash; // Default to 0
……
}
5. 字段/属性注释
例如:
public class EmailBody implements Serializable{
private String id;
private String senderName;//发送人姓名
private String title;//不能超过120个中文字符
private String content;//邮件正文
private String attach;//附件,如果有的话
private String totalCount;//总发送人数
private String successCount;//成功发送的人数
private Integer isDelete;//0不删除 1删除
private Date createTime;//目前不支持定时 所以创建后即刻发送
privateSet<EmailList> EmailList;
……
}
相关文章
- 暂无相关文章
用户点评