Comments

Single-line and Multi-line Comments

Example

Comments are ignored by the compiler. Use them to explain why, not what.

fun main() {
    // This is a single-line comment
    println("Hello") // comment at the end of a line

    /* This is a
       multi-line comment */
    println("World")

    /* Kotlin allows /* nested */ block comments, Java does not */
    // println("This line will not run")
}

Output

Hello
World

KDoc Documentation Comments

KDoc comments start with /** and document functions and classes. IDEs show them on hover, and Dokka turns them into HTML docs (like Javadoc for Java).

/**
 * Calculates the delivery fee for an order.
 *
 * @param distanceKm distance from restaurant to customer
 * @return fee in rupees
 */
fun deliveryFee(distanceKm: Double): Int = if (distanceKm <= 3) 20 else 40

Tip: Use Ctrl + / (Cmd + / on Mac) in IntelliJ or Android Studio to comment or uncomment the selected lines.