Wednesday, August 25, 2010

dynamic fields with groovy

one of the features I love is to just define new fields in objects whenever I want.


def test = ["a","b","c,"]

Object a = new Object()


a.metaClass."${it}" = it

generates te following fields in the object a

a.a = "a"
a.b = "b"
a.c = "c"

works incredible well with the grails export plugin :)