|
Groovy example source code file (ClosureInStaticMethodTest.groovy)
The Groovy ClosureInStaticMethodTest.groovy source code
package groovy
/**
* @author <a href="mailto:james@coredevelopers.net">James Strachan
* @version $Revision: 4996 $
*/
class ClosureInStaticMethodTest extends GroovyTestCase {
void testClosureInStaticMethod() {
def closure = closureInStaticMethod()
assertClosure(closure)
}
void testMethodClosureInStaticMethod() {
def closure = methodClosureInStaticMethod()
assertClosure(closure)
}
static def closureInStaticMethod() {
return { println(it) }
}
static def methodClosureInStaticMethod() {
System.out.&println
}
static def assertClosure(Closure block) {
assert block != null
block.call("hello!")
}
void testClosureInStaticMethodCallingStaticMethod() {
assert doThing(1) == 10
assert this.doThing(1) == 10
assert ClosureInStaticMethodTest.doThing(1) == 10
}
static doThing(count) {
def ret = count
if (count > 2) return ret
count.times {
ret += doThing(count+it+1)
}
return ret
}
}
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy ClosureInStaticMethodTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.