Feelin' Groovy.

Groovy 3.0: New default parser & Java-style Lambda syntax

Sarah Schlothauer
© Shutterstock / dexterous simpson

After several release candidates and years of work, welcome the latest version of Groovy: version 3.0. This Java-syntax-compatible language hits a new milestone and adds plenty of improvements and brand new capabilities. The biggest change in Apache Groovy 3.0 is the new parser, Parrot, which adds support for additional syntax and new language features.

Apache Groovy 3.0 has arrived and it includes a host of new features that make it more flexible and integrates with newer Java features. For starters, it includes a new default parser (currently under the code-name Parrot) and support for Java-style Lambda syntax.

Groovy is a Java-syntax-compatible object-oriented language. With its familiar syntax and by working on top of the JVM, it is easy to integrate directly with any Java program. While Groovy isn’t currently as loved as younger languages that use the JVM, such as Kotlin, the 3.0 release introduces a few new changes that might shake things up.

So, is it time to bust out Groovy again in 2020?

SEE ALSO: OutOfMemoryError related JVM arguments

New Parser; meet Parrot.

The biggest highlight of v3.0.0 is the new parser, Parrot. Under the hood, it is more flexible and maintainable and includes support for additional syntax and language features. Parrot includes all the current language features, but it also adds a few new ones.

From the new parser’s README on GitHub, these new features include:

  • do-while loops; enhanced (now supporting commas) classic for loops, e.g. for(int i = 0, j = 10; i < j; i++, j--) {..})
  • lambda expressions, e.g. -> e + 1)
  • method references and constructor references
  • try-with-resources, AKA ARM
  • code blocks, i.e. {..}
  • Java style array initializers, e.g. new int[] {1, 2, 3}
  • default methods within interfaces
  • additional places for type annotations
  • new operators: identity operators(===!==), elvis assignment(?=), !in!instanceof
  • safe index, e.g. nullableVar?[1, 2]
  • non-static inner class instantiation, e.g. Inner()
  • runtime groovydoc, i.e. groovydoc starting with /**@; groovydoc attached to AST node as metadata

In 3.0, the new parser is enabled by default and can be disabled via a system property if necessary. With future versions of Groovy, the old parser will be deprecated and then removed.

From the repository, be sure to read the open discussion of Groovy 3 changes, written by Apache Groovy PMC Member Daniel Sun.

Embeddable Groovydocs

In 3.0, Groovy takes inspiration from languages such as Ruby. Users can now embed Groovydocs in a few different ways. (The revamped tool is still under development.)

  • Groovydocs can be made available within the AST and gets stored as a node metadata. Users can enable this feature with the groovy.attach.groovydoc system property or the flag in CompilerConfiguration.
  • Any Groovydoc comment that starts with a /**@ opening comment delimite can be embedded into the class file and stored in a @Groovydoc annotation. Users can enable this feature with the groovy.attach.runtime.groovydoc system property or the flag in CompilerConfiguration.

SEE ALSO: Top Java technologies in 2020 – JVM programming languages, IDEs, tools & more

Groovy 4?

While we are looking at v3.0, the language is already ahead of itself. According to the release notes for v3.0, “Groovy 3 is making changes to allow the codebase to move towards the compliant rules and allow Groovy users to begin the migration process. Groovy 4 is our target version for fully-compliant artifacts but you can start getting your classes ready ahead of time while using Groovy 3“.

The development team expects alpha releases of Groovy 4 soon.

Upgrading to the latest version

Whether you’ve been using Groovy all along, or hope to check out the new features and see how it compares to more commonly used alternatives, check out version 3.0. As a prerequisite, you will need JDK9+ in order to build.

View the download page and follow one of the several ways to get groovin’.

Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is the editor for She received her Bachelor's degree from Monmouth University, West Long Branch, New Jersey. She currently lives in Frankfurt, Germany with her husband and cat where she enjoys reading, writing, and medieval reenactment. She is also the editor for Conditio Humana, an online magazine about ethics, AI, and technology.

Inline Feedbacks
View all comments