在Kotlin v1.1 +中,可以选择声明类型别名 ,这为别的类型提供了替代名称。 这对于函数类型特别有用 - 例如:
typealias OnItemClick = (view: View, position: Int) -> Boolean和其他成员一样,他们可以通过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但是有没有特定的方法来记录函数类型的参数和返回类型?
Kotlin网站提供了关于记录Kotlin代码的信息 ,但没有提及类型。
像函数本身一样,如果函数类型可以像这样记录,那将会很好:
/** * @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中无法识别。
那么应该如何记录参数和返回类型?
In Kotlin v1.1+, there is the option of declaring type aliases, which provide alternative names for existing types. This is particularly useful for function types - for example:
typealias OnItemClick = (view: View, position: Int) -> BooleanAnd they can be documented with KDoc comments, like other members:
/** * Type definition for an action to be preformed when a view in the list has been clicked. */ typealias OnItemClick = (view: View, position: Int) -> BooleanBut is there a specific way of documenting the parameters and return type of the function type?
The Kotlin website provides information on documenting Kotlin code, but makes no mention of typealiases.
Like functions themselves, it would be nice if function types could be documented like this:
/** * @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) -> BooleanBut the tags aren't recognised in KDoc.
So how should the parameters and return types be documented?
最满意答案
不幸的是,目前在KDoc中没有特别的支持来记录参数和返回值到函数类型的类型,所以您只需要将它们描述为文档的一部分。 我提交了一项功能请求以添加支持。
Unfortunately at this time there is no special support in KDoc for documenting parameter and return values for typealiases to function types, so you just need to describe them as part of the documentation. I've filed a feature request to add the support.
更多推荐
发布评论