如何记录Kotlin功能类型?

Far*_*deh 8 type-alias kotlin kdoc

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

typealias OnItemClick = (view: View, position: Int) -> Boolean
Run Code Online (Sandbox Code Playgroud)

与其他成员一样,他们可以使用KDoc评论进行记录:

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

但是有没有一种特定的方法来记录函数类型的参数和返回类型?

Kotlin网站提供了有关记录Kotlin代码的信息,但未提及typealases.

就像函数本身一样,如果函数类型可以像这样记录下来会很好:

/**
 * @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
Run Code Online (Sandbox Code Playgroud)

但是在KDoc中无法识别标签.

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

yol*_*ole 6

不幸的是,目前在KDoc中没有特别支持将typealases的参数和返回值记录到函数类型,因此您只需要将它们描述为文档的一部分.我已提交功能请求以添加支持.