Sunday 13 January 2019

Groovy: Comments


Comments makes the program more readable.

Suppose you written thousand lines of program, without proper documentation, after some time, for the owner of the application also, it is very difficult to figure out what was written.

Groovy support three kind of comments.
a.   Single line comments
b.   Multi line comments
c.    GroovyDoc comments

Single line comments
Single line comments starts with //
// It is a single line comment

HelloWorld.groovy
//Below statement prints the message to console.
println "Hello World"

Multi line comments
Multi line comments are placed inbetween /* */
/* I am a mulltiline comment */

HelloWorld.groovy
/*      Below statement prints
         the message to console */
println "Hello World"

GroovyDoc comments
GroovyDoc commetns are similar to multiline comments, these start with /** and end with */.

GroovyDoc follows the same convention like JavaDoc tags, you can use the same convention. For more information on JavaDoc tags, I would recommend you go through my below tutorial series.

HelloWorld.groovy
/**
* Class defines an Employee
*/
class Employee{
  /**
  * Property represents first name of an employee
  */
  String firstName
  
  /**
  * Property represents last name of an employee
  */ 
  String lastName
  
  String getFullName(){
    return firstName + "," + lastName
  }
}

Employee emp = new Employee()
emp.setFirstName("Krishna")
emp.setLastName("Gurram")

println emp.getFullName()


Previous                                                 Next                                                 Home

No comments:

Post a Comment