代码之家  ›  专栏  ›  技术社区  ›  Paul McKenzie

在注释之前还是之后放置javadoc?

  •  168
  • Paul McKenzie  · 技术社区  · 14 年前

    我知道这不是最重要的问题,但我刚刚意识到我可以在注释之前或之后放置JavaDoc注释块。我们希望采用什么作为编码标准?

    /**
     * This is a javadoc comment before the annotation 
     */
    @Component
    public class MyClass {
    
        @Autowired
        /**
         * This is a javadoc comment after the annotation
         */
        private MyOtherClass other;
    }
    
    4 回复  |  直到 11 年前
        1
  •  178
  •   n00begon Priidu Neemre    11 年前

    在注释之前,因为注释是“属于”类的代码。 见 examples with javadoc 在官方文件中。

    以下是我在 another official Java page :

    /**
     * Delete multiple items from the list.
     *
     * @deprecated  Not for public use.
     *    This method is expected to be retained only as a package
     *    private method.  Replaced by
     *    {@link #remove(int)} and {@link #removeAll()}
     */
    @Deprecated public synchronized void delItems(int start, int end) {
        ...
    }
    
        2
  •  16
  •   Christian Seifert    14 年前

    我同意已经给出的答案。

    Annotations are part of the 代码 而JavaDoc是 文档 (因此得名)。

    所以对我来说,保持代码部分在一起是合情合理的。

        3
  •  11
  •   shadrik    11 年前

    除了编码标准之外,如果JavaDoc工具放置在注释之后,JavaDoc工具似乎不处理Java文档注释。否则工作正常。

        4
  •  10
  •   Robby Pond    14 年前

    一切都归结为可读性。在我看来,使用方法/字段正上方的注释,代码更易于阅读。