【发布时间】: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