documentation - 在 Kotlin 中记录函数参数的参数

标签 documentation kotlin higher-order-functions

假设我有一个高阶函数,它注册了某种点击监听器。我可以记录它的用途和传入的 listener 参数:

/**
 * Adds a [listener] that's called when the item is clicked.
 *
 * @param listener The listener to add
 */
fun addClickListener(listener: (count: Int) -> Unit) {
    ...
}

我的问题是,有没有办法记录 listener 的参数?在此示例中,这将是 count。在我的实际用例中,我的监听器中有多个参数。

我注意到,在我使用此功能的文档 View 中,[listener] 文本是可点击的,但它只显示一个关于它的空对话框。有没有办法以某种方式描述那里的参数?

enter image description here The listener documentation that comes up

现在,我最终在 addClickListener 方法中使用 @param block 描述了监听器的参数,但这会导致 IDE 中出现警告,我想知道是否有更合适的方法。

最佳答案

从 Kotlin 1.1 开始,没有语法来记录用作函数参数的函数类型的参数或返回值。有一个 open YouTrack issue覆盖这个。

关于documentation - 在 Kotlin 中记录函数参数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43574868/

相关文章:

documentation - 如何记录应用程序以及它们如何与其他应用程序集成?

javascript - JsDoc 工具包和命名空间 - 警告尝试..而不

android - lateinit属性mMap尚未初始化

spring-boot - 指定为非 null 的参数在 Kotlin 中为 null

javascript - 错误: function is not defined when calling a function returned by another function

documentation - 如何在Doxygen的 Markdown 文档之间链接?

angular - 如何用 Angular 编写我的函数的文档

c# - LINQ 相对于函数式方法链的优势

scala - Scala 中的柯里化(Currying)与匿名函数

lambda - 范围函数 apply/with/run/also/let : Where do their names come from?