Beginner 4 min readKotlin 2.0

Kotlin Comments โ€” Single-Line, Multi-Line, and KDoc

Comments make code easier to understand. Kotlin supports three types: single-line, multi-line, and KDoc for documentation.

What You Will Learn

  • Single-line comments with //
  • Multi-line comments with /* */
  • KDoc comments for documentation
  • When to use each type

Single-Line Comments

Use // to write a comment that ends at the end of the line. The compiler ignores everything after //.

Single-Line Comments

kotlin
// This program calculates a sum
fun main() {
    val a = 10 // first number
    val b = 20 // second number
    println(a + b) // print the result
}
Output
30

Everything after // on a line is ignored by the compiler. You can put a comment at the end of a code line.

Beginner Tip: Write comments to explain WHY you wrote the code, not WHAT it does โ€” the code itself shows what it does.

Multi-Line Comments

Use /* ... */ for comments that span multiple lines. Kotlin also supports nested multi-line comments.

Multi-Line Comment

kotlin
/*
    This program demonstrates
    multi-line comments.
    They can span many lines.
*/
fun main() {
    println("Comments are invisible to the compiler")
}
Output
Comments are invisible to the compiler

Everything between /* and */ is ignored. Unlike Java, Kotlin supports nested /* */ comments.

KDoc Comments

KDoc is Kotlin's documentation comment system (similar to JavaDoc). Use /** ... */ to document functions, classes, and properties. IDEs display KDoc when you hover over declarations.

KDoc Comment

kotlin
/**
 * Adds two integers and returns their sum.
 *
 * @param a The first number.
 * @param b The second number.
 * @return The sum of a and b.
 */
fun add(a: Int, b: Int): Int = a + b

fun main() {
    println(add(3, 4))
}
Output
7

@param documents each parameter. @return documents the return value. The dokka tool generates HTML documentation from KDoc comments.

Best Practice: Write KDoc for all public functions and classes. Skip KDoc for private helpers and one-line utility functions where the name is self-explanatory.

Practice Exercise

Exercisemultiple choice

Which type of comment is used for generating API documentation?

Quick Quiz

Quick Quiz

Can Kotlin multi-line comments be nested?

Frequently Asked Questions

Related Tutorials

Last updated: 2026-05-01Kotlin 2.0

Written by KotlinGuide Editorial Team ยท Reviewed by KotlinGuide Technical Review