There are four ways to annotate groovy, and here's a more detailed look:
1.1 Single-line comment
In groovy, single-line comments start with//and can start anywhere in a row, with the following characters being the annotations section. For example:
A standalone single line comment
println "Hello World"//A comment till the end of ofthe line
1.2 Multi-line comments
A multiline comment starts with/* and ends with the first */end that is encountered, and in an expression, such a comment can exist, for example:
/*a Standalone Multiline Comment
Spanning lines */
println "Hello"/* a multiline commentstarting
At the end of Astatement */
PRINTLN 1/* One */+2/*two */
1.3 Groovydoc Notes
Similar to the Javadoc comment in Java, Groovydoc starts with/** and ends with */, can be used for multiple lines, each line in the middle starts with a *, and this annotation can be used for (1) type definition (class,interface,enum,annotation). (2) domain and attribute definitions, (3) method definitions.
Since Groovydoc uses the same document converter as the Java-Javadoc, labels in Javadoc are also available in Groovydoc.
For example:
/**
* A Class Description
*/
Class person{
/** the name of the person * *
Stringname
/**
* Creates a greeting method for acertain person.
*
* @param otherperson the person Togreet
* @return a GreetingMessage
*/
String greet (string Otherperson) {
"Hello ${otherperson}"
}
}
1.4 Transaction column (Shebang line)
This is a special way of line commenting that allows groovy scripts to run directly on the command line of a UNIX system, as long as the computer has a groovy environment installed and the path system variable contains a groovy path.
For example:
#!/usr/bin/envgroovy
println "Hellofrom The Shebang line"
Note # must be the first character (the starting character) of the script file.