Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Groovy doesn't yet support setting properties on (non-static) inner classes using named arguments, as in code below
class MyOuterClass { def foo() { def ic = new MyInnerClass(fName: 'Roshan', lName: 'Dawrani') } class MyInnerClass { def fName def lName } } def oc = new MyOuterClass() oc.foo()
The code above fails with the message
failed to invoke constructor: public MyOuterClass$MyInnerClass(MyOuterClass) with arguments: [] reason: java.lang.IllegalArgumentException: wrong number of arguments
indicating that the implicit "this" reference is not being passed as the first argument.
Supporting above usage may require significant changes possibly.
The bit related to "this" not being passed implicitly can be corrected in the meantime - so that at least the following works fine
class MyOuterClass { def foo() { def ic = new MyInnerClass(fName: 'Roshan', lName: 'Dawrani') } class MyInnerClass { Map propMap def MyInnerClass(Map propMap) { this.propMap = propMap } } } def oc = new MyOuterClass() oc.foo()