Groovy Syntax Compared to Java

Despite the overall syntactic similarities, there are some differences between Groovy and Java that are worth noting. The first thing you’ll notice in a block of Groovy code is the lack of semicolons; in Groovy, semicolons are optional. Return statements are also optional. If there is no return statement in a method, then the last statement evaluated is returned. Sometimes this makes sense, especially in the case of small methods that simply return a value or perform a single calculation. Other times it can be confusing. That’s the beauty of the word optional. When return makes code more readable, use it; when it doesn’t, don’t.

Parentheses for method calls are optional in most cases, the exception being when ...

Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.