首页 > 解决方案 > 用 KDoc 注释变量的正确方法是什么?

问题描述

我试图像@property 一样进行注释,但这是不对的。多卡不认识

例如枚举:

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

标签: kotlinkdoc

解决方案


您可以查看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)
}

或者,您还可以记录类文档中的属性:

/**
 * 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) {
    // ...
}

推荐阅读