codestyle; put javadoc before or after annotation?

五迷三道 提交于 2019-11-28 04:26:09
Peter Jaric

Before the annotation, since the annotation is code that "belongs" to the class. See examples with javadoc in the official documentation.

Here's random example I found in 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) {
    ...
}

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.

Apart of the coding standard, it seems that javadoc tool doesn't process the java doc comments if they are placed after the annotations. Works fine otherwise.

It all comes down to readablity. In my opinion code is more readable with the Annotations directly above the method/field.

I agree with all of the above. It may be helpful to others that IntelliJ (Idea)'s code style templates fail both falsely positive (when @throws is specified correctly, it warns) and falsely negative (when @throws is not specified, but should be) when using RestEasy style annotations. I put my javadocs above everything else, then annotations, then code.

See the bug report here: https://youtrack.jetbrains.com/issue/IDEA-220520

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!