Just the Cure, More Groovy

| by Craig Wickesser Follow 0 Followers on Mar 01, 2009. Estimated reading time: 2 minutes |

Actor Christopher Walken once performed a skit on Saturday Night Live in which he proclaimed he needed more cowbell to get rid of his "fever".  In the same light, the Groovy team has certainly heard the calls for more Groovy and have recently released 1.6 of their award winning language.  There are a slew of new features mentioned in the release including,

  • great runtime performance improvements
  • multiple assignments - optional return in if/else and try/catch blocks
  • AST transformations and all the provided transformation annotations like @Singleton, @Lazy, @Immutable, @Delegate and friends
  • the Grape module and dependency system and its @Grab transformation
  • various Swing builder improvements, thanks to the Swing / Griffon ( team
  • as well as several Swing console improvements
  • the integration of JMX builder
  • JSR-223 scripting engine built-in
  • various metaprogramming improvements, like the EMC DSL, per-instance metaclasses even for POJOs, and runtime mixins

One of the primary focuses in this release was on performance and the Groovy team claims to have made significant improvements ranging from 150% to 460%.  Another feature included in this release was the official integration of the JMX builder, which is just another example of community efforts helping to improve Groovy.

Below are some examples of several of the new features including multiple assignments and AST transformations.

// this class' properties are immutable once the object is constructed
@Immutable final class ServerConfig {
  String url
  int port

def getServerInfo() {
  ['', 8080]

// attempts to set a property on an Immutable object
def setUrl(config, newUrl) {
  try {
    config.url = newUrl
  catch (ReadOnlyPropertyException ex) {

// multiple assignment
def (url, port) = getServerInfo()

assert url == ''
assert port == 8080

def config = new ServerConfig(url, port)

assert config.url == url
assert config.port == port

// try to change the property on the Immutable object
def result = setUrl(config, '')

// verify the property change failed
assert result instanceof ReadOnlyPropertyException

The example above shows how the @Immutable AST transformation provides a very simple way of creating a read-only object.  The example also demonstrates using the new "multiple assignments" feature.  For more information about the AST transformations you can visit the Groovy user guide, currently the section only covers the @Immutable transformation.

Now that you've seen a quick overview of what Groovy 1.6 has to offer, check out What's New in Groovy 1.6, an in-depth article about Groovy 1.6 written for InfoQ by the Groovy Project Manager, Guillaume LaForge.  Guillaume covers each of the new features and provides plenty of code examples which help clarify all of the new capabilities.

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

Grape and grab are pretty nice by andrej koelewijn

The build in dependency management makes life a lot easier, especially for scripting. Nice example on my blog with Apache Camel: Groovy and Grape - easiest way to send gtalk message with Apache Camel?.

1.6 is really more effective than 1.5.7 by qiu james

But groovy need to improve startup speed.
gant is too slow so we have to rewrite it in python, or beanshell.

congrats by Roger Pack

congrats to the groovy guys.

JRuby or Groovy? by Joshua Partogi

That is the question now.

Re: JRuby or Groovy? by Guillaume Laforge

That is the question now.

Groovy, of course ;-)

Re: JRuby or Groovy? by Marcio Garcia

Why not both of them? :)

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

6 Discuss