簡體   English   中英

使用 KDoc 注釋變量的正確方法是什么?

[英]What is the proper way to annotate variable with KDoc?

我試圖像 @property 一樣進行注釋,但這是不對的。 多卡不承認

例如枚舉:

enum class Vegetables(val id: Int) {
    POTATO(1),
    CARROT(2),
    CUCUMBER(3)
}

您可以查看Kotlin 文檔,了解如何在代碼中添加文檔注釋。

您可以將文檔放在您想要記錄的地方。

/**
 * Here goes your main Vegetables type doc.
 *
 * You can refer to the [id] constructor argument like this.
 */
enum class Vegetables(
    /**
     * Here goes the doc for your id constructor argument and property.
     */
    val id: Int
) {
    /**
     * Here goes the doc for POTATO.
     */
    POTATO(1),
    /**
     * Here goes the doc for CARROT.
     */
    CARROT(2),
    /**
     * Here goes the doc for CUCUMBER.
     */
    CUCUMBER(3)
}

或者,您也可以記錄 class 文檔中的屬性:

/**
 * Here goes your main Vegetables type doc.
 *
 * You can refer to the [id] constructor argument like this.
 *
 * @property id You can also document the id property this way
 */
enum class Vegetables(val id: Int) {
    // ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM