Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.1.9, 2.2.2, 2.4.0-rc-1
-
None
-
None
-
Ubuntu Linux
Oracle JDK 1.7.0_45 64-bit
Groovy 2.2.2
Groovy 2.1.9
Description
Creating an anonymous subclass of class that implements a propertyMissing setter with return type of "def" results in a compilation error:
// This code does not work class FooA { Map m = [:] def propertyMissing(String name, def value) { m[name] = value } } // This statement produces a compilation error def anonSubclass = new FooA(){}
The compilation error is as follows:
1 compilation error: The return type of void propertyMissing(java.lang.String, java.lang.Object) in ConsoleScript7$1 is incompatible with java.lang.Object propertyMissing(java.lang.String, java.lang.Object) in FooA . At [-1:-1] at line: -1, column: -1
Declaring and instantiating a named subclass of FooA produces no errors.
// This code works. class FooB extends FooA {} def namedSubclass = new FooB()
As a workaround, the propertyMissing setter can be declared with a "void" return type.
// This code works class FooC { Map m = [:] void propertyMissing(String name, def value) { m[name] = value } } def anonSubclass2 = new FooC(){}