This material was written by Aasmund Eldhuset; it is owned by Khan Academy and is licensed for use under CC BY-NC-SA 3.0 US. Please note that this is not a part of Khan Academy's official product offering.
Kotlin's documentation syntax is called KDoc. A KDoc block is placed above the construct it describes, and begins with /**
and ends with */
(possibly on one line; if not, each intermediate lines should start with an aligned asterisk). The first block of text is the summary; then, you can use block tags to provide information about specific parts of the construct. Some block tags are @param
for function parameters and generic type parameters, and @return
for the return value. You can link to identifiers inside brackets. All the text outside of links and block tag names is in Markdown format.
/** * Squares a number. * * @param number Any [Double] number whose absolute value is * less than or equal to the square root of [Double.MAX_VALUE]. * @return A nonnegative number: the result of multiplying [number] with itself. */ fun square(number: Double) = number * number
Package-level documentation can be provided in a separate Markdown file.
Unlike docstrings, KDoc blocks are not available to the program at runtime.
You can generate separate documentation files in HTML format from KDoc by using a tool called Dokka.
← Previous: Scoped resource usage
© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/docs/tutorials/kotlin-for-py/documentation.html