• Java doc注释


    常用Java注释标签(Java comment tags)

    @author 作者

    适用范围:文件、类、方法

    多个作者使用多个@author标签标识,java doc中显示按输入时间顺序罗列。)
    例:* @author Leo. Yao

    @param 输入参数的名称 说明

    适用范围:方法

    例:* @param str the String用来存放输出信息。

    @return 输出参数说明

    适用范围:方法

    例: * @return true执行成功;

    false执行失败.

    @since JDK版本

    用于标识编译该文件所需要的JDK环境。

    适用范围:文件、类

    例: * @since JDK1.6

    @version 版本号

    用于标识注释对象的版本号
    适用范围:文件、类、方法
    例: * @version 1.0

    @see 链接目标

    表示参考。会在java 文档中生成一个超链接,链接到参考的类容。
    用法
    @see #field
    @see #Constructor(Type, Type...)
    @see #Constructor(Type id, Type id...)
    @see #method(Type, Type,...)
    @see #method(Type id, Type, id...)
    @see Class
    @see Class#field
    @see Class#Constructor(Type, Type...)
    @see Class#Constructor(Type id, Type id)
    @see Class#method(Type, Type,...)
    @see Class#method(Type id, Type id,...)
    @see package.Class
    @see package.Class#field
    @see package.Class#Constructor(Type, Type...)
    @see package.Class#Constructor(Type id, Type id)
    @see package.Class#method(Type, Type,...)
    @see package.Class#method(Type id, Type, id)
    @see package

    @throws 异常

    标识出方法可能抛出的异常

    适用范围:方法

    例: * @throws IOException If an input or output exception occurred

    @deprecated废弃

    标注此类/接口、方法、字段已经被废止

    适用范围:文件、类、方法

    链接到一个目标,用法类似@see。但常放在注释的解释中形如{@link …}

    /**
        - @deprecated      As of JDK 1.1, replaced by
        - {@link #setBounds(int,int,int,int)}
     */
    
    

    Java注释的使用顺序

    • @author (classes and interfaces only, required)
    • @version (classes and interfaces only, required. See footnote 1)
    • @param (methods and constructors only)
    • @return (methods only)
    • @exception (@throws is a synonym added in Javadoc 1.2)
    • @see
    • @since
    • @serial (or @serialField or @serialData)
    • @deprecated (see How and When To Deprecate APIs)

    常见注释模板

    类(接口)注释

    ​```java
    /**

    • 类的描述
    • @author Administrator
    • @Time 2012-11-2014:49:01

    */
    public classTest extends Button {
    ……
    }

    
    
    
    ## 方法注释
    
    ```java
    public class Test extends Button {
      /**
    
    - 为按钮添加颜色
    - @author Administrator
    - @param color
    - @return
    - @exception  (方法有异常的话加)
    - @Time2012-11-20 15:02:29
    */
      public voidaddColor(String color){
    ……
      }
    }
    

    全局变量注释

    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;
    ……
    }
    

    字段/属性注释

    public class EmailBody implements Serializable{
       private String id;
       private String senderName;//发送人姓名
       private String title;//不能超过120个中文字符
       private String content;//邮件正文
       private String attach;//附件,如果有的话
       privateSet<EmailList> EmailList;
    ……
    }
    
  • 相关阅读:
    Android开发之动态设置字体的样式和粗细
    Android开发之炫酷MD风格
    Android开发之自定义Dialog简单实现
    Android开发之自定义Toast(带详细注释)
    【Android优化篇】提升Activity加载速度的方法
    android使用Pull解析来自服务器的xml文件时出现错误以及解决方案
    Image augmentation for machine learning experiments
    LibreCAD
    C++ library to read and write DXF/DWG files
    DXF-Viewer
  • 原文地址:https://www.cnblogs.com/ngrzr/p/11906340.html
Copyright © 2020-2023  润新知