方法注释和注释......各自应该去哪里?
所以, 假设我有一个包含注释的方法,如下所示:
@Override
public void bar(String x)
如果我要将 Javadoc 注释添加到这段代码中,哪种方法是首选方法?
要么:
/**
* @param x A string lol
*/
@Override
public void bar(String x)
或者:
@Override
/**
* @param x A string lol
*/
public void bar(String x)
So,
lets say I have a method that contains an annotation like so:
@Override
public void bar(String x)
If I were to add Javadoc comments to this snippet of code, which is the preferred method?
Either:
/**
* @param x A string lol
*/
@Override
public void bar(String x)
Or:
@Override
/**
* @param x A string lol
*/
public void bar(String x)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
第一个。注释适用于方法,而不是注释。这也是大多数 IDE 都会做的事情,因此也是最常见的。
First one. The annotation applies to the method, not the comment. It's also what most IDEs will do, so is the most common anyway.
就我个人而言,我更喜欢前者(即注释“触及”方法签名),因为那时它是代码与代码。
但两者都适用于编译器,因此这取决于个人品味/您组织的编码标准。
Personally, I prefer the former (i.e. annotation "touching" the method signature), since then it's code with code.
But either works for the compiler, so it's down to personal taste/your organisation's coding standards.
意见:第一种方法更可取。在某种程度上,注释和方法的结合比注释更强。
Opinion: The first method is preferable. In a way the annotation and the method belongs together stronger than the comment.
一般来说,注释是在方法之前的一行(或多行)上的坑。注释放在同一行可能有点长。
然而,@Override 有点特殊。它有效地弥补了语言没有
覆盖
的缺陷。按照惯例,它被放置在同一行(尽管您会看到很多不是这样的例子)。Generally annotations are pit on the line (or lines) immediately before the method. Annotations can be a bit long to put on the same line.
However,
@Override
is a bit special. It's effectively making up for the language not havingoverride
. Conventionally it is placed on the same line (although you'll see plenty of examples where it isn't).