Groovy 2.3 Released With Traits and Java 8 Support

| by Victor Grazi Follow 14 Followers on May 06, 2014. Estimated reading time: 3 minutes |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

Groovy Project Manager at Pivotal Guillaume Laforge today announced the release of Groovy 2.3, the first major Groovy release this year, and the first major release of Groovy to feature official support for running on the recently released Java 8.

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 { 
    String fly() { "I'm flying!" }
Then we create a class, Bird, that implements that trait, and instantiate it:
class Bird implements FlyingAbility {}

def b = new Bird()

We can check that the Bird instance does have the new fly() method mixed-in:

assert == "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.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you