Experience Groovy 1.8

Groovy - Home

Experience Groovy 1.8

Groovy 1.8 is the latest major and stable version of the popular dynamic language for the JVM. To learn more about the novelties, make sure to read the release notes. In a nutshell, Groovy 1.8 provides new Domain-Specific Language authoring capabilities for more readability and expressivity of your business rules, runtime performance improvements, the bundling of the GPars parallel and concurrency library, built-in JSON support, new compile-time meta-programming features (several new useful AST transformations), new functional programming aspects for closures, and much more.




"Groovy is like a super version of Java. It can leverage Java's enterprise capabilities but also has cool productivity features like closures, builders and dynamic typing. If you are a developer, tester or script guru, you have to love Groovy."









Samples

A simple hello world script:

def name='World'; println "Hello $name!"

A more sophisticated version using Object Orientation:

class Greet {
  def name
  Greet(who) { name = who[0].toUpperCase() +
                      who[1..-1] }
  def salute() { println "Hello $name!" }
}

g = new Greet('world')  // create object
g.salute()               // output "Hello World!"

Leveraging existing Java libraries:

import static org.apache.commons.lang.WordUtils.*

class Greeter extends Greet {
  Greeter(who) { name = capitalize(who) }
}

new Greeter('world').salute()

On the command line:

groovy -e "println 'Hello ' + args[0]" World
原文地址:https://www.cnblogs.com/lexus/p/2369406.html