Kotlin Comments

Kotlin Comments

Comments are used to explain the code for those who see your code or read your code, like your team mates or someone who maintains the code, or uses the code somehow.

Comments are ignored by the program execution.

There are two types of comments, based on the number of lines a comment spans.

  1. Single-line comments
  2. Multi-line comments

Single-line comments

A single-line comment starts with a // symbol, and you can write anything after that symbol, in that line, as a comment.

Kotlin Program

fun main(args: Array<String>) {
    // This is a single-line comment
    println("Hello World!")
}

More about single line comments in Kotlin.

Multi-line comments

A multi-line comment starts with a /* symbol, followed by the multi-line comment text, then ends with a */.

Kotlin Program

fun main(args: Array<String>) {
    /* This is a
       multi-line comment */
    println("Hello World!")
}

More about multiline comments in Kotlin.