Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Groovy uses a similar syntax to Java although in Groovy semicolons are optional.
This saves a little typing but also makes code look much cleaner (surprisingly so for such a minor change). So normally if one statement is on each line you can ommit omit semicolons altogether - though its it's no problem to use them if you want to. If you want to put multiple statements on a line use a semicolon to separate the statements.


Code Block
def geocode(String location) {
    // implementation returns [48.824068, 2.531733] for Paris, France
    [48.824068, 2.531733]

def (_lat, lon_long) = geocode("Paris, France")

assert _lat == 48.824068
assert lon_long == 2.531733

And you can also define the types of the variables in one shot as follows: