Groovy 3.0 has introduced a lot of features from Java 7 and 8. Here are some features try-with-resource, identity common comparison,!in, !instanceof, etc.
Streamlining Python Development: A Guide to a Modern Project Setup
Preview of Groovy 3
1. Preview of Groovy 3.0
Presented by Vijay Shukla (vijay@nexthoughts.com)
2. Agenda
1. Parrot Parser
2. Improve the loop statement
3. Do-while statement
4. Supports Lambda Expressions
5. Support Method and Constructor Reference
6. Support try-with resource statement
7. Support Java-style array initialization
8. Support interface default method
9. New Operator
10. Support for secure retrieval
11. Support runtime Groovydoc
3. Parrot Parser
It has new parser Parrot which is far more flexible and maintainable thank the
previous versions of groovy.
It is enabled by default in Groovy 3.*
We can disable it by using a system property.
Use -Dgroovy.antlr4=false (set it via JAVA_OPTS)
4. Improve the loop statement
Comma-separate expression is now supported. (Java Syntax)
Do-While has been introduced.
Groovy support multi assignment since 1.6 but now it also supported in for loop.
5. Java Style Array Initialization
Groovy has always supported literal list/array definitions using square brackets ([])
and has avoided Java-style curly braces just to not conflict with closures.
6. Lambda Expressions
The Normal Variants of Java Lambda Expression supported in Groovy 3.0
● General Form
● Curly braces are optional for single expression
● Parameter Types are optional
● No Parenthesis required for a single parameter with no type
● No argument case
It has additional features such as default parameter value.
7. Method and Constructor Reference
Java 8 method reference syntax using double colon syntax is now supported.
9. Try with Resource
Java 7’s has try-with-resource statement for ARM (Automatic Resource
Management).
Groovy 3.0 also support the same syntax as Java 7.
10. Interface Default Method
Java 8 supports adding default implementations to interfaces. Groovy now
supports this too.
12. Extra Stuff
@Canonical:- It allows you to write classes in shortened form. It provide
combination of features of @ToString, @EqualsAndHashcode, @TupleConstructor.
@ToString:- default implementation of toString() method on the basis of fields in
class
@EqualsAnd Hashcode:- default implementation of equals() and hashcode().
@TupleConstructor:- provide classical constructor with default properties.
Constructor implementation depends upon the order of the variable declaration.
All above are defined in groovy.transform package