`
fox.tan
  • 浏览: 63252 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

怎么样写Java注释

 
阅读更多

 

How to Write Doc Comments for the Javadoc Tool

 

 

A Style Guide

The following are useful tips and conventions for writing descriptions in doc comments.

    • Use <code> style for keywords and names. 
      Keywords and names are offset by <code>...</code> when mentioned in a description. This includes:

    • Java keywords
    • package names
    • class names
    • method names
    • interface names
    • field names
    • argument names
    • code examples
    • Use in-line links economically 
      You are encouraged to add links for API names (listed immediately above) using the {@link} tag. It is not necessary to add links for all API names in a doc comment. Because links call attention to themselves (by their color and underline in HTML, and by their length in source code doc comments), it can make the comments more difficult to read if used profusely. We therefore recommend adding a link to an API name if:

    • The user might actually want to click on it for more information (in your judgment), and
    • Only for the first occurrence of each API name in the doc comment (don't bother repeating a link)

Our audience is advanced (not novice) programmers, so it is generally not necessary to link to API in the java.lang package (such as String), or other API you feel would be well-known.

  • Omit parentheses for the general form of methods and constructors 
    When referring to a method or constructor that has multiple forms, and you mean to refer to a specific form, use parentheses and argument types. For example, ArrayList has two add methods: add(Object) and add(int, Object):

    The add(int, Object) method adds an item at a specified position in this arraylist.

    However, if referring to both forms of the method, omit the parentheses altogether. It is misleading to include empty parentheses, because that would imply a particular form of the method. The intent here is to distinguish the general method from any of its particular forms. Include the word "method" to distinguish it as a method and not a field.

    The add method enables you to insert items. (preferred)

    The add() method enables you to insert items. (avoid when you mean "all forms" of the add method)

  • OK to use phrases instead of complete sentences, in the interests of brevity.
    This holds especially in the initial summary and in @param tag descriptions.

  • Use 3rd person (descriptive) not 2nd person (prescriptive). 
    The description is in 3rd person declarative rather than 2nd person imperative.

    Gets the label. (preferred)

    Get the label. (avoid)

  • Method descriptions begin with a verb phrase. 
    A method implements an operation, so it usually starts with a verb phrase:

    Gets the label of this button. (preferred)

    This method gets the label of this button.

  • Class/interface/field descriptions can omit the subject and simply state the object.
    These API often describe things rather than actions or behaviors:

    A button label. (preferred)

    This field is a button label. (avoid)

  • Use "this" instead of "the" when referring to an object created from the current class.
    For example, the description of the getToolkit method should read as follows:

    Gets the toolkit for this component. (preferred)

    Gets the toolkit for the component. (avoid)

  • Add description beyond the API name.
    The best API names are "self-documenting", meaning they tell you basically what the API does. If the doc comment merely repeats the API name in sentence form, it is not providing more information. For example, if method description uses only the words that appear in the method name, then it is adding nothing at all to what you could infer. The ideal comment goes beyond those words and should always reward you with some bit of information that was not immediately obvious from the API name.

    Avoid - The description below says nothing beyond what you know from reading the method name. The words "set", "tool", "tip", and "text" are simply repeated in a sentence.

     

    /**
     * Sets the tool tip text.
     *
     * @param text  the text of the tool tip
     */
    public void setToolTipText(String text) {
     Preferred - This description more completely defines what a tool tip is, in the larger context of registering and being displayed in response to the cursor.
    /**
     * Registers the text to display in a tool tip.   The text 
     * displays when the cursor lingers over the component.
     *
     * @param text  the string to display.  If the text is null, 
     *              the tool tip is turned off for this component.
     */
    public void setToolTipText(String text) {
  • Be clear when using the term "field".
    Be aware that the word "field" has two meanings:

  • static field, which is another term for "class variable"
  • text field, as in the TextField class. Note that this kind of field might be restricted to holding dates, numbers or any text. Alternate names might be "date field" or "number field", as appropriate.
  • Avoid Latin
    use "also known as" instead of "aka", use "that is" or "to be specific" instead of "i.e.", use "for example" instead of "e.g.", and use "in other words" or "namely" instead of "viz."

 

分享到:
评论

相关推荐

    java的注释规范(单行注释、多行注释、分块注释)

    java 注释规范是 Java 开发过程中不可或缺的一部分,它的目的是让项目中所有的文档都看起来像一个人写的,增加可读性,减少项目组中因为换人而带来的损失。java 注释规范可以分为三种:单行注释、多行注释和分块注释...

    Java注释规范

    Java 注释规范是为了让项目中所有的文档都看起来像一个人写的,增加可读性,减少项目组中因为换人而带来的损失。该规范定义了 Java 项目中注释的规范和要求,包括注释的类型、注释的内容、注释的位置、注释的格式等...

    java注释模板

    eclipse中java类注释模板,有需要的朋友可以参考使用。

    Java注释模板使用

    Java注释模板的使用就是一种确保代码风格统一的有效方法。本文将深入探讨Java注释的类型、用途,以及如何创建和使用注释模板,以帮助您和您的团队提升代码质量。 1. **Java注释类型**: - **单行注释**:以`//`...

    Java的注释

    本文将详细介绍几种常见的Java注释方式及其用途,并通过实例展示如何设置Eclipse IDE中的注释模板,帮助开发者更好地管理和组织代码。 #### 一、Java注释概述 Java提供了三种类型的注释: 1. **单行注释(//)**:...

    Eclipse Java 注释模板

    下面我们将深入探讨Eclipse Java注释模板的使用方法、重要性以及如何进行自定义配置。 首先,Eclipse的Java注释模板允许开发者预先设定一系列常用的注释格式,如类、方法、变量的注释模板。这些模板包含了如作者、...

    Eclipse Java注释模板.txt

    ### Eclipse Java注释模板知识点详解 #### 一、概述 在进行Java开发的过程中,良好的代码注释习惯不仅能帮助自己快速回顾代码逻辑,还能方便其他开发者理解代码意图,从而提高整个团队的工作效率。Eclipse作为一款...

    java 注释模板 超级好用

    超级好用的 java 注释模板,吐血总结,整理。吐血总结,整理。

    java 注释模板

    java 注释模板 java 注释模板 java 注释模板 java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板java 注释模板

    Java代码注释率检查器.rar

    Java代码注释是编程实践中非常重要的一个环节,它有助于提高代码的可读性和维护性。注释能够解释代码的功能、用途以及实现逻辑,使得其他开发者能更快地理解代码,尤其在团队协作中更是不可或缺。本资源"Java代码...

    Java注释全解文档

    Java注释是编程过程中的重要组成部分,它们不仅有助于提高代码的可读性和可维护性,还能为其他开发者提供代码的功能解释和使用指南。本篇全解文档深入探讨了Java注释的各种类型及其在不同框架中的应用,如Hibernate...

    java注释规范文档

    ### Java注释规范详解 #### 一、引言 在软件开发过程中,代码注释扮演着极其重要的角色。良好的注释不仅可以帮助其他开发者快速理解代码的功能和用途,还能提高整个团队的工作效率。Java作为一种广泛使用的编程...

    java注释模板.zip

    Java注释模板就是为了帮助开发者快速、规范地添加注释而设计的。本文将深入探讨Java注释模板的重要性、类型以及如何使用。 一、注释模板的重要性 1. 提高代码可读性:良好的注释能够清晰地解释代码的功能、逻辑和...

    java开发代码注释情况统计工具

    这是本人自己开发的一款java代码注释统计工具,支持统计总行数,总代码行数,总注释行数,注释率,注释合格率自定义,统计详细,单个文件统计情况,可导出统计报告等! 注:本软件未捆绑jre(java环境),需要在已...

    java 注释风格和java格式风格模版

    首先,Java注释风格主要有三种: 1. 单行注释:使用`//`标记,常用于快速添加临时性的或者行内的注释。 2. 多行注释:使用`/* */`包裹,适合对代码块进行解释,可以跨越多行。 3. Javadoc注释:以`/** */`形式存在...

    java注释规范

    Java 注释规范详解 Java 注释规范是 Java 语言中一个非常重要的部分,它不仅能够提高代码的可读性和可维护性,还能够帮助其他开发者更好地理解代码的逻辑和意图。下面我们将详细介绍 Java 注释规范的各个方面。 ...

    如何更好的规范java 注释

    在软件开发中,Java注释是提高代码可读性和维护性的重要组成部分。本文将详细介绍Java注释的规范,帮助开发者更好地理解和遵循注释的最佳实践。 首先,注释的作用在于为其他开发者提供代码的清晰解释,使得他们在...

    java代码注释模板

    Java代码注释是编程实践中非常重要的一个环节,它有助于提高代码的可读性和维护性。在团队合作中,良好的代码注释能够帮助其他开发者更快地理解代码的功能和逻辑,节省了阅读和调试的时间。本资源包含一个“java代码...

    清除Java代码注释

    本篇文章将详细探讨如何在Java项目中有效地清除注释。 首先,我们来看一下使用MyEclipse这个强大的Java集成开发环境(IDE)来清除注释的方法。MyEclipse是基于Eclipse定制的一个版本,提供了许多方便的开发工具和...

Global site tag (gtag.js) - Google Analytics