2007-11-16

Groovy Class tricks

jwagon sent me these mind bending groovy class manipulations in a chat today:

#!/usr/bin/env groovy

class AA {
def msg
AA(something){ msg = something }
}

def c = { a, b ->
def x =a.newInstance(b)
println x.msg
}

c(AA, "foo")


Or how about....

#!/usr/bin/env groovy
def m = java.lang.String
def n = m.newInstance("foo")
println n