GNU Free Documentation License . .

Groovy

: ,
Groovy
Groovy-logo.png
:

2003

():

:

2.0 (27 2011 [1][2])

:

:

Java, Ruby, Python, Perl, Smalltalk

:

http://groovy.codehaus.org

Groovy  - Java Java Python, Ruby Smalltalk.

Groovy Java- JVM - Java . Java .

Groovy Java Community Process JSR 241.

Groovy ( Java):

[]

class Foo {
  def doSomething() {
    def data = ["name": "James", "location": "London"]
    for (e in data) {
      println("entry ${e.key} is ${e.value}")
    }
  }
 
  def closureExample(collection) {
    collection.each { println("value ${it}") }
  }
 
  static void main(args) {
    def values = [1, 2, 3, "abc"]
    def foo = new Foo()
    foo.closureExample(values)
    foo.doSomething()
  }
}

[]

Groovy

Groovlets  Groovy .

GroovyBeans  Groovy JavaBeans.

Java, Groovy , main Runnable GroovyTestCase:

#!/usr/bin/env groovy
println "I can execute this script now!"

Groovy: Java Strings GStrings .

def javaStyleString = 'java String style'
def GStringsStyleString = "${javaStyleString}"
def j = '${javaStyleString}' 
def bigGroovyString = """
    ${javaStyleString}
    ${GStringsStyleString}
"""
println bigGroovyString

Groovy (setColor(String color) getColor()):

class AGroovyBean {
  String color
}
 
def myGroovyBean = new AGroovyBean()
 
myGroovyBean.setColor('blue')
assert myGroovyBean.getColor() == 'blue'
 
myGroovyBean.color = 'green'
assert myGroovyBean.color == 'green'

Groovy , :

def myList = ['One', 'Two', 'Three']  //  ,   
assert myList[2] == 'Three'
myList[3] = 'Four'  //   
assert myList.size() == 4
 
def monthMap = [ 'January' : 31, 'February' : 28, 'March' : 31 ]  // 
assert monthMap['March'] == 31  
monthMap['April'] = 30  //   
assert monthMap.size() == 4

Closure () :

def closureFunction = {a, b ->
    println a
    println b
}
 
closureFunction(1, 2)

return   .

Immutable:

@Immutable
class ImmutableClass {
    String stringVariable
    Integer integerVariable
}
def newVariable = new ImmutableClass(stringVariable : "some string", integerVariable : 23)

[]

Groovy (. James Strachan (programmer))[3] 2003 . 2004 2006 . , JCP, , «1.0». «1.0» , 2 2007 . 2007 Groovy 1.1, «1.5» .

Groovy 1.0 2007 , 2009 , Groovy, 2003 (. Martin Odersky) Scala ( 2007 )[4].

JSR-241 2007 (Guillaume Laforge).

[] IDE

Groovy [5], :

[] Groovy

iReport, java- JasperReports, Groovy .

Hudson , Groovy.

[] .

[]

  1. Groovy 1.8.0 final is released (.)
  2. Groovy 1.8 (.)
  3. James Strachan. Groovy  the birth of a new dynamic language for the Java platform
  4. Scala as the long term replacement for java/javac? (July 6, 2009). 10 2012. 7 2012. «I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 Id probably have never created Groovy»
  5. IDE Groovy

[]