Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting parameters of a function parameter in Kotlin

Let's say I have a higher order function, which registers some sort of a click listener. I can document its purpose and the listener parameter that's passed in like so:

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

My question is, is there a way to document the parameters of the listener? This would be count in this example. In my actual use case, I have multiple parameters in my listener.

What I've noticed is that the [listener] text is clickable in the documentation view where I'm using this function, but it just shows an empty dialog about it. Is there a way to describe the parameters there somehow?

enter image description here The listener documentation that comes up

For now, I've ended up describing the parameters of the listener with @param blocks at the addClickListener method, but this results in a warning in the IDE, and I'm wondering if there's a more proper way to do it.

like image 912
zsmb13 Avatar asked Oct 31 '25 05:10

zsmb13


1 Answers

As of Kotlin 1.1 there is no syntax for documenting the parameters or return value of a function type used as a function parameter. There is an open YouTrack issue covering this.

like image 62
yole Avatar answered Nov 02 '25 11:11

yole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!