198

我知道这不是最重要的问题,但我刚刚意识到我可以将 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

5 回答 5

212

在注解之前,因为注解是“属于”类的代码。请参阅官方文档中的javadoc 示例。

这是我在另一个官方 Java 页面中找到的随机示例:

/**
 * 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) {
    ...
}
于 2010-06-24T12:37:00.373 回答
18

I agree with the answers already given.

Annotations are part of the code while javadoc is part of the documentation (hence the name).

So for me it seams reasonable to keep the code parts together.

于 2010-06-24T13:05:01.240 回答
14

除了编码标准之外,如果将 javadoc 注释放在注释之后,javadoc 工具似乎不会处理它们。否则工作正常。

于 2013-10-25T08:49:37.563 回答
13

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

于 2010-06-24T12:38:22.393 回答
0

我同意以上所有观点。在使用 RestEasy 样式时,IntelliJ (Idea) 的代码样式模板可能会在误报(正确指定 @throws 时发出警告)和误报(当未指定 @throws 时,但应该如此)失败,这可能对其他人有所帮助注释。我把我的 javadocs 放在一切之上,然后是注释,然后是代码。

在此处查看错误报告: https ://youtrack.jetbrains.com/issue/IDEA-220520

于 2019-08-12T17:38:55.990 回答