In this tutorial you will learn about the Kotlin Comments and its application with practical example.
Kotlin Comments
In Kotlin, Comments are a set of statements that are ignored by the Kotlin interpreter. The use of comments makes it easy for humans to understand the source code.Usually comments gives you inside or explanation about the variable, method, class or any statement that exists in source code. The comment statements are ignored during the execution of the program.
Kotlin Single-line Comments:-
A ‘//’ (double slash) is used to specify a single line comment, which extends up to the newline character.
1 2 3 4 |
fun main(args: Array<String>) { // It prints Hello World println("Hello World!") } |
Output:-
1 |
Hello World! |
Kotlin Multi-line Comments:-
If you want to comment multiple lines then you can do it using
/*
and */
, everything in between from /*
to */ is ignored by the compiler
–
1 2 3 4 5 |
fun main(args: Array<String>) { /* It prints Hello World! */ println("Hello World!") } |
Output:-
1 |
Hello World! |