Kotlin Comments

4. Kotlin Comments 4.1 Kotlin comment uses 4.2 Types of kotlin comments


Kotlin comment uses

The comment is a developer guideline which does not visible on the screen and exists only for the human reader. The purpose of commenting is only to know in the future what you did, or guideline for future modifications. Comments are invaluable for helping the next person who understands your code to figure out problems and aware that what you were thinking when you wrote it. This is also helpful even when that person is yourself, a month from now, because generally we forget what we did one month ago. It is good practice to write comments for every function, class, property in your code.


Kotlin comment types

Kotlin supports two types of comments - Block comments and line comments.

Line Comments

Kotlin line comment is c++ style one line comment. The compiler ignores everything starting from // to the end of the line.

Example

// This is C++ style one line comment supported in Kotlin.

Block Comments

The Kotlin block comment is multiline comment, the compiler ignores everything in between /* and */.

Example

/* This is a
multiple line
comment supported
in Kotlin
*/

In kotlin, block comments can be nested.








Read more articles