【问题标题】:Kotlin static field value in method documentation? [duplicate]方法文档中的 Kotlin 静态字段值? [复制]
【发布时间】:2019-08-07 06:49:01
【问题描述】:

我想知道是否有可能将类的静态字段的值包含到类方法的文档中。

我们可以通过方括号链接类成员和参数:

/**
 * Sets the title of the notification dialog using [title]
 *
 * The maximum title length allowed is [MAX_TITLE_LENGTH]
 */
fun setTitle(title: String): NotificationDialog.Builder {
    if(title.length <= MAX_TITLE_LENGTH)
        mTitle = title
    else
        mTitle = title.substring(0, MAX_TITLE_LENGTH)

    return this
}

目标

但我希望在方法文档中包含 MAX_TITLE_LENGTH 的值,而不是指向其名称的链接。

为了完整起见,这是我的类定义:

class Builder(val context: Context) {
    private var mTitle = ""

    /**
     * Sets the title of the notification dialog using [title]
     *
     * The maximum title length allowed is [MAX_TITLE_LENGTH]
     */
    fun setTitle(title: String): NotificationDialog.Builder {
        if(title.length <= MAX_TITLE_LENGTH)
            mTitle = title
        else
            mTitle = title.substring(0, MAX_TITLE_LENGTH)

        return this
    }

    fun build(): NotificationDialog {
        return NotificationDialog(context, mTitle)
    }

    companion object {
        private const val MAX_TITLE_LENGTH = 20
    }
}

提前致谢。

【问题讨论】:

  • 我没找到这个! +1 谢谢。

标签: kotlin kdoc


【解决方案1】:

没有这样的事情,因为 KDoc 是基于标记语言的。取而代之的是,使用方括号允许您在类的属性之间进行链接。在此处查看更多信息:https://kotlinlang.org/docs/reference/kotlin-doc.html#inline-markup

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-19
  • 1970-01-01
  • 2018-04-29
  • 1970-01-01
  • 1970-01-01
  • 2020-04-27
  • 2017-07-15
相关资源
最近更新 更多