Skip to content
Advertisement

How to add a KDoc comment for the receiver of a Kotlin extension function (first parameter in Java, `this` in Kotlin)

Consider this non-extension function:

JavaScript

When I use this function in kotlin and java, I can see its parameter name: expression.

I could also write this same functionality as an extension function:

JavaScript

When I write it as an extension function in this manner, the parameter name of the Boolean that it is called on (the this variable within the function, AKA the receiver) shows up as $this$checkArguments. How can I add a KDoc documentation comment for this parameter? Using @param $this$checkArguments doesn’t seem to document it.

Advertisement

Answer

You can use @receiver to document the receiver of the extension function. Here is the relevant documentation.

For example:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement