Gro.
Groovy 2.3 adds support for "traits", as well as many new and improved AST transformations like @TailRecursive, @Builder and @Sortable. A new NIO2 module with Path support has also been added, as well as greatly optimized JSON parsing and building, closure parameter type-inference, a new markup template engine, Groovysh and GroovyConsole ease of use improvements, a new GroovyAssert test utility, more @BaseScript class capabilities, and other features.
InfoQ spoke to Groovy Produce Manager Guillaume Laforge about the release.
InfoQ: Congratulations on another great release of Groovy. Can you tell us about the main features?
Guillaume: The two big highlights of this release are our implementation of traits, which allows developers to compose behaviors more elegantly than with classes and interfaces alone, making it easier to promote reuse.
As an example, let's look at the following code sample of traits in action:trait FlyingAbility {Then we create a class, Bird, that implements that trait, and instantiate it:
String fly() { "I'm flying!" }
}class Bird implements FlyingAbility {}
def b = new Bird()
We can check that the Bird instance does have the new fly() method mixed-in:assert b.fly() == "I'm flying!"
That's just a simple example.
The other big feature is the support of JDK 8. You can run Groovy 2.3 on JDK 8, use Groovy closures in lieu of lambdas, or reuse all the new APIs (like date / time, etc) of JDK 8 from Groovy.
InfoQ: What about the performance impact?
Guillaume: There are various places where we did some performance fine-tuning, to turn some slow path to faster path (for instance optimizing some call paths to compile them statically more efficiently, or making better use of "invoke dynamic" in dynamic areas, etc.) One big area where you'll see a noticeable and drastic improvement is with our JSON support, both for parsing and serializing, as Matt Raible recently covered in an article on InfoQ.
InfoQ: Are there any changes to frameworks you are providing or consuming?
Guillaume: We upgraded our various dependencies to recent versions, for instance the ASM library that we use for generating our bytecode, as ASM 5 provides support for generating Java 8 bytecode (for instance for lambdas, interface default methods, etc). The Groovy distribution also comes with the recently released GPars 1.2, our go-to library for concurrency, parallelism, and asynchronicity. GPars 1.2, features various improvements, for instance in the dataflow handling (with lazy tasks, easy fork-join on "Promises").
InfoQ: What is left on the horizon?
Guillaume: There are still things we're working on: we're rewriting our documentation from scratch, making it "executable" by testing all the code samples included as part our build. There's already a lot of content, but still many sections to fill in! And the Groovy team gladly welcomes any contribution in this area! We also plan to overhaul our website with a fresher look, new documentation, and more readable API docs. On the longer-term aspects, some of the thing's we're working on are:
- A new and more coherent dynamic runtime (our "Meta-Object Protocol"),
- Rewriting our grammar. It would still be the same Groovy syntax, but this would make it easier for the Groovy development team to continue evolving the language syntax when we decide to introduce new syntax constructs.
- Some of the new Java 8 syntax constructs will likely become part of the Groovy syntax as well, including future enhancements to the JDK 8 APIs.
You can learn more about the new features of Groovy 2.3 by reading the release notes.