Skip to main content
A block comment in Kotlin is a lexical construct used to instruct the compiler to ignore a specific span of text. It is delimited by the /* character sequence at the beginning and the */ character sequence at the end. The enclosed text can span multiple lines or be placed inline within a single statement. Standard Syntax
Nested Block Comments Unlike Java and C++, Kotlin’s lexical analyzer supports nested block comments. When the compiler encounters a nested /*, it increments an internal depth counter and requires a corresponding */ to decrement it before terminating the outer comment. This prevents premature termination errors when commenting out large sections of code that already contain existing block comments.
KDoc Distinction A block comment that begins with an extra asterisk (/**) is structurally distinct and treated as a KDoc comment. While it shares the same termination syntax (*/) and nesting capabilities as a standard block comment, its contents are parsed into an Abstract Syntax Tree (AST) by the Kotlin documentation engine (Dokka) to generate API references.
Tired of Poor Kotlin Skills? Fix That With Deep Grasping!Learn More