2010-06-24 31 views
148

我知道這不是最重要的問題,但我意識到我可以在註釋之前或之後放置javadoc註釋塊。我們希望採用什麼作爲編碼標準?codestyle;在註釋之前或之後放入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; 
} 

回答

158

在註解之前,由於註釋是「屬於」類的代碼。 請參閱官方文檔中的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) { 
    ... 
} 
+6

此處也有趣 - 註釋與方法的其他限定符位於同一行。我從來沒有見過這樣做,但似乎表明註釋應該像對其他方法的限定符一樣對待,因此,javadoc應該一直在它之前。 – ArtOfWarfare 2013-11-06 18:42:09

+5

如果您使用像Jackson這樣的重要註記,那麼將相同的註釋放在同一行上可能會很快失控。我把每個註釋放在它自己的一行上。 – 2015-04-10 02:43:52

8

這一切都歸結到可讀性 - 。在我看來,直接在方法/字段之上的註釋使得代碼更具可讀性。

11

我同意已經給出的答案。

註解是代碼而javadoc的是文檔(因此命名)的一部分的一部分。

所以對我來說它合理的代碼部分保持在一起。

8

除了編碼標準,似乎javadoc工具不處理java doc註釋,如果它們放在註釋之後。否則工作正常。

相關問題