Groovy 10 – Comments and Key Words


Comments are part of the code we write that will be ignore by the groovy console

Comments are used to explain the code we are making so that others or even ourselves can understand it later.

There are 2 types of comments:

-Single Line

– Multi-line

Single line comments are done using double slash //


  1. def x =1  
  2. def z =2  
  3. // This part will be ignored by the console  
  4. def y =x + Z  

Multi-line as the name says, can be written on multiple lines and are signaled by encapsulating the lines in between /*  and */


  1. def a = 3  
  2. /* 
  3. This is a 
  4. comment on 
  5. multiple 
  6. lines 
  7. */  
  8. def c = a + 7  

Key Words

This words are reserved words in groovy

That means that they can not be used as variable names or for other purpose except the one that they have been assigned to.

Here is a table of this keywords


This means this words can not be used for example as variable names:

def new = 11

Doing this will give an error when trying to save your script.


but if you do def random = new Random()

This will not give you an error, as new keywords is used in the way it was designed to be used in groovy.


Leave a Reply

Your email address will not be published. Required fields are marked *