Missing setProperty() ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Missing setProperty() ?

Paul Bennett
I'm sure someone has observed this before, but I can't find any reference. Apologies if this is obvious, but ....

I'm confused as to why this:

class Test {

    def prop
   
    void setProperty(String name,Object val) {
        super.setProperty(name,val)
    }
}

def t = new Test()
t.prop = 1
println t.prop

throws a MissingMethod exception when executed:

ERROR groovy.lang.MissingMethodException:
No signature of method: Test.setProperty() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [prop, 1]
Possible solutions: setProperty(java.lang.String, java.lang.Object), getProperty(java.lang.String), hasProperty(java.lang.String), getProperties()

1) The error message seems to imply that there IS a super implementation, as it suggests what I would expect to be the superclass implementation
2) If you remove the override of setProperty(), it - of course -  works fine.

It would seem that the compiler stops generating the superclass method implementation (presumably from GroovyObjectSupport) when you define setProperty() explicitly on a top-level Groovy class. This seems inconvenient, as it precludes the above implementation, which can reuse the super behavior.

Am I just missing some thing obvious?

This is from Groovy 1.7.8 in Eclipse, GroovyConsole and the command line


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Missing setProperty() ?

Jochen Theodorou
Am 17.03.2011 16:01, schrieb Paul Bennett:

> ERROR groovy.lang.MissingMethodException:
> No signature of method: Test.setProperty() is applicable for argument types: (java.lang.String, java.lang.Integer) values: [prop, 1]
> Possible solutions: setProperty(java.lang.String, java.lang.Object), getProperty(java.lang.String), hasProperty(java.lang.String), getProperties()
>
> 1) The error message seems to imply that there IS a super
> implementation, as it suggests what I would expect to be the superclass
> implementation

the exception text simply takes the wrong class as base for the text you
see. It prints a setProperty method, because Test has one, but super to
Test is Object and that has none.

> 2) If you remove the override of setProperty(), it - of course -
> works  fine.

because the compiler adds the method.

> It would seem that the compiler stops generating the superclass
> method  implementation (presumably from GroovyObjectSupport) when you define
> setProperty() explicitly on a top-level Groovy class. This seems
> inconvenient, as it precludes the above implementation, which can reuse
> the super behavior.

look at the bytecode, Test does not extend GroovyObjectSupport, instead
it only implements GroovyObject and the compiler adds the missing
methods unless you provide them yourself. If you want it to extend
GroovyObjectSupport, then you will have to write that into the class
declaration and then of course your super call will work as well

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead
http://blackdragsview.blogspot.com/
For Groovy programming sources visit http://groovy.codehaus.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email