Groovy
Um die Groovy Konsole zu starten, klicke hier: Groovy Konsole.
Contents
Hello Worlds
print "Hello World"
Closures
Simple Klammer. it ist defaultmässig der Parameter.
myclosure = {it + it} myclosure(4)
Klammer mit zwei Paremetern:
myprint = {first, last -> print "[" + first + ", " + last + "]"} myprint("hugo","boss")
Classes
Interfaces
Implementation eines einfachen Interfaces:
x = {print "hello"} as Runnable x.run()
Definition und Implementation eines Interfaces mit mehreren Methoden:
interface X { void f1(); void f2(int n) }
x = {Object[] args -> println "method called with $args"} as X x.f1() x.f2(1)
Der Output ist:
method called with null
method called with {1}