Tutorial by Examples

Since Groovy 1.8 a convenient memoize() method is added on closures: // normal closure def sum = { int x, int y -> println "sum ${x} + ${y}" return x + y } sum(3, 4) sum(3, 4) // prints // sum 3 + 4 // sum 3 + 4 // memoized closure def sumMemoize = sum.memoize() ...
Since Groovy 2.2 groovy.transform.Memoized annotation is added to convenient memoize methods with simply adding the @Memoized annotation: import groovy.transform.Memoized class Calculator { int sum(int x, int y){ println "sum ${x} + ${y}" return x+y } ...

Page 1 of 1