| Warning This page was created to report about the changes in syntax when we switched to a new parser back in 2004. So some of the points below are not necessarily representative of what Groovy supports nowadays. Please take the notes below with a grain of salt! |
Here is a checklist of changes you'll need to make to a Groovy classic codebase to ensure compatibility with the new Groovy JSR syntax.
In Classic Groovy we used to use this syntax
Instead of using the arrow operator for safe navigation to avoid NullPointerException, we're now using the ?. operator
Now in the JSR we use this syntax
This allows us to use one single token for the separator between the closure in Classic Groovy we used to use this syntax
Now in the JSR we use this syntax
This allows us to use one single token for the separator between the closure parameters and the code in in the closure which works with arbitrarily complex parameter list expressions and default values. e.g.
For Scripts (as opposed to explicitely declared classes) the syntax is not changed, i.e. variable declarations without 'def' are still allowed, because those variables are automatically created in the script binding if they don't already exist.
The default access level for members of Groovy classes has changed from "public" to "protected"
Classic Groovy
Now in JSR Groovy
This is to avoid ambiguity with things like ranges (1..2) and so forth
In classic Groovy you could access method pointers automatically if there was no java bean property of the given method name.
e.g.
This often caused confusion; as folks would use a property access to find something and get a method by accident (e.g. typo) and get confused. So now we make getting a method pointer explicit as follows
Due to ambiguity, we've not yet added support for do .. while to Groovy
NOT YET IMPLEMENTED
Previously, in Groovy Classic, we used the backward slash as the integer division operator. This operator being confusing with escaping sequences was removed. So instead of \ please use the intdiv() method.
Becomes
The operator for creating ranges with the upper bound excluded from the range has changed.
Instead of:
The syntax is now: