Skip to main content

Kotlin Comments

Comment is describe the sorted explanation of code logic. Normally comment is an documented text for programmers. This document text can be helpful for other programmer those are read this code or modified modified that code. When multiple programmer are working together. Then comment is useful to understand other programer logic and working explanation.

Compiler is ignored comment portion and that is not executable. Kotlin comment is very similar to java, c and c++ and c# programing language.

Type of kotlin comments

That is divided into three section single line comment,multi line comment and doc comment.

Single Line

Single line comment are used to distribute small and sorter explanation of code. That is start with double forward slash (//). Generally single line comment are used to explain expression and statement in programming. There syntax as follows.

//this is comment text

For example.

//Example of single line comment
fun main(args: Array<String>){
   
   //define two integers
   var x:Int =10
   var y:Int =20
   //add both values
   var result:Int=x+y
   //display sum 
   println(result)
}

Output

30

Muti-line comments

When explanation documented text is more then one line so in this case we can use multi line comment.There syntax as follows.

/*this is comment text
second line 
thired line commented text */

For Example

/*
   Function : sum
   Parameters : accepted two integer values
   default parameters value: 0
   return : sum of two integers
*/
fun sum(x:Int = 0 , y:Int =0):Int{
   return x+y
}
fun main(args: Array<String>){
   print(sum(1,2));
}

Output

3

Doc comment

Documented comment are similar to multi line comment, There text are define within the (/**) and (*/).

/**
*   Function :settings
*   Parameters: non
*   @return : Integer result
*/
fun settings():Int{
  //body of function
}




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment