【问题标题】:How should Kotlin function typealises be documented?应该如何记录 Kotlin 函数类型化?
【发布时间】:2018-08-19 00:17:00
【问题描述】:

在 Kotlin v1.1+ 中,可以选择声明 type aliases,它为现有类型提供替代名称。这对于函数类型特别有用 - 例如:

typealias OnItemClick = (view: View, position: Int) -> Boolean

并且可以像其他成员一样使用 KDoc cmets 记录它们:

/**
 * Type definition for an action to be preformed when a view in the list has been clicked.
 */
typealias OnItemClick = (view: View, position: Int) -> Boolean

但是有没有具体的方法来记录函数类型的参数和返回类型?

Kotlin 网站提供了有关 documenting Kotlin code 的信息,但没有提及类型别名。

就像函数本身一样,如果函数类型可以这样记录就更好了:

/**
 * @param view       the view that was clicked
 * @param position   the layout position from the ViewHolder (see
                     [ViewHolder.getLayoutPosition])
 * @return whether the click was successful
 */
typealias OnItemClick = (view: View, position: Int) -> Boolean

但是 KDoc 中无法识别标签。

那么应该如何记录参数和返回类型呢?

【问题讨论】:

    标签: kotlin type-alias kdoc


    【解决方案1】:

    不幸的是,此时 KDoc 中没有特别支持将类型别名的参数和返回值记录为函数类型,因此您只需将它们描述为文档的一部分。我已经提交了feature request 以添加支持。

    【讨论】:

      猜你喜欢
      • 2011-12-03
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 2021-12-26
      • 2023-03-08
      相关资源
      最近更新 更多