A few notes of groovy Codex Groovy

Source: Internet
Author: User
Tags comments shebang

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.