Groovy: Named parameter constructors
groovy
Solution
Seems like Groovy needs explicit reference to an instance of the 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"
Problem
I found really cool that one can do: ``` class Foo { String name } def foo = new Foo(name:"Test") ``` But, it only works when my file name matches the class name. If I have a file with a bunch of classes like: ``` class AllClassesInOneFile { class Bar {} class Foo { String name } } def foo = new Foo(name:"Test") ``` Now, it does not work anymore I get a java.lang.IllegalArgumentException: wrong number of arguments I wonder if it is still possible to invoke named parameter argument style with scripts and nested classes. Regards