Closures - Groovin' with Groovy | [ Prev | Home | Next ] |
class Point { x y Point(x,y) { this.x = x; this.y = y } eachCoordinate(closure) { closure.call(x) closure.call(y) } } p = new Point(10, 20) counter = 0 p.eachCoordinate { counter += 1 } println "The point has ${counter} dimensions"
Example 10
Copyright 2004 by Jim Weirich (Some Rights Reserved) |