Comments
Comments are part of the code we write that will be ignored by the Groovy console. They are used to explain the code so that others or even ourselves can understand it later. There are two types of comments:
- Single Line
- Multi-line
Single Line Comments
Single line comments are done using double slash //
Example:
- def x = 1
- def z = 2
- // This part will be ignored by the console
- def y = x + z
Multi-line Comments
Multi-line comments can be written on multiple lines and are enclosed between /* and */
Example:
- def a = 3
- /*
- This is a
- comment on
- multiple
- lines
- */
- def c = a + 7
Key Words
These words are reserved in Groovy, meaning they cannot be used as variable names or for other purposes except for what they are assigned to.
Here is a table of these keywords:
Source: Groovy Syntax
This means these words cannot 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 keyword is used in the way it was designed to be used in Groovy.