Show Menu
Cheatography

KDoc Cheat Sheet (DRAFT) by

A cheatsheet for KDoc, the language used to document Kotlin code.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Block Tags

@param
Documents a value parameter of a function or a type parameter of a class, property or function.
@param[name]
To better separate the parameter name from the descri­ption, if you prefer, you can enclose the name of the parameter in brackets.
@return
Documents the return value of a function.
@const­ructor
Documents the primary constr­uctor of a class.
@receiver
Documents the receiver of an extension function.
@property
Documents the property of a class which has the specified name. This tag can be used for docume­nting properties declared in the primary constr­uctor, where putting a doc comment directly before the property definition would be awkward.
@throws class, @exception class
Documents an exception which can be thrown by a method. Since Kotlin does not have checked except­ions, there is also no expect­ation that all possible exceptions are docume­nted, but you can still use this tag when it provides useful inform­ation for users of the class.
@sample identi­fier
Embeds the body of the function with the specified qualified name into the docume­ntation for the current element, in order to show an example of how the element could be used.
@see identi­fier
Adds a link to the specified class or method to the See also block of the docume­nta­tion.
@author
Specifies the author of the element being docume­nted.
@since
Specifies the version of the software in which the element being documented was introduced
@suppress
Excludes the element from the generated docume­nta­tion. Can be used for elements which are not part of the official API of a module but still have to be visible extern­ally.

Example

/**
 * A group of *members*.
 *
 * This class has no useful logic; it's just a documentation example.
 *
 * @param T the type of a member in this group.
 * @property name the name of this group.
 * @constructor Creates an empty group.
 */
class Group<T>(val name: String) {
    /**
     * Adds a [member] to this group.
     * @return the new size of the group.
     */
    fun add(member: T): Int { ... }
}