creating proxy object in groovy

Posted by IttayD on Stack Overflow See other posts from Stack Overflow or by IttayD
Published on 2010-05-16T15:36:38Z Indexed on 2010/05/16 15:40 UTC
Read the original article Hit count: 146

Filed under:

Hi,

I am looking for how to write a method that accepts some value and returns a proxy to that value where the underlying value can be retrieved with an accessor:

def p = toProxy(1)
assert p == 1
assert p * 2 == 2
assert p.underlying == 1

def p2 = toProxy(objWithMethodFoo)
p2.foo()
p2.underlying.foo()

I want to do this per object instance (not for all objects of some class) and without the need to use special 'use' constructs.

© Stack Overflow or respective owner

Related posts about groovy