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
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"
Non-static nested object can't exist without instance of the outer class. The same in java. Just change nested object to static.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With