So, lets say I have a method that contains an annotation lik开发者_运维百科e 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)
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.
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 having override
. Conventionally it is placed on the same line (although you'll see plenty of examples where it isn't).
精彩评论