如何记录Kotlin函数的类型化?(How should Kotlin function typealises be documented?)

编程入门 行业动态 更新时间:2024-10-25 21:21:38
如何记录Kotlin函数的类型化?(How should Kotlin function typealises be documented?)

在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) -> Boolean

And 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) -> Boolean

But 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) -> Boolean

But 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.

更多推荐

本文发布于:2023-08-06 11:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1448631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   类型   Kotlin   documented   typealises

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!