Sunday, 15 May 2011

Groovy: Named parameter constructors -



Groovy: Named parameter constructors -

i found cool 1 can do:

class foo { string name } def foo = new foo(name:"test")

but, works when file name matches class name. if have file bunch of classes like:

class allclassesinonefile { class bar {} class foo { string name } } def foo = new foo(name:"test")

now, not work anymore java.lang.illegalargumentexception: wrong number of arguments

i wonder if still possible invoke named parameter argument style scripts , nested classes.

regards

seems groovy needs explicit reference instance of outer class:

class baz { class bar {} class foo { string name } } def baz = new baz() def f = new baz.foo(baz, [name: "john doe"]) assert f.name == "john doe"

groovy

No comments:

Post a Comment