[ 
https://issues.apache.org/jira/browse/GROOVY-2412?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King closed GROOVY-2412.
-----------------------------

> Need to access the metaClass of a subclass before receiving the dynamic 
> methods that are added to the superclass
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-2412
>                 URL: https://issues.apache.org/jira/browse/GROOVY-2412
>             Project: Groovy
>          Issue Type: Sub-task
>          Components: groovy-runtime
>    Affects Versions: 1.5
>         Environment: Groovy Version: 1.5.0 JVM: 1.6.0_03-b05
>            Reporter: René de Bloois
>            Priority: Major
>
> This script works:
> {code}
> class Super
> {
>       def test2() { println "test2" }
> }
> Super.metaClass.test3 = { println "test3" }
> class Sub extends Super
> {
>       def test4() { println "test4"; super.test3() }
> }
> Sub.metaClass // Does not work without this line
> new Super().test2()
> new Super().test3()
> new Sub().test2()
> new Sub().test3()
> new Sub().test4()
> {code}
> It outputs:
> {code}
> test2
> test3
> test2
> test3
> test4
> test3
> {code}
> But when I remove the commented line (Sub.metaClass), it does not work 
> anymore. You get the following stacktrace:
> {code}
> test2
> test3
> test2
> Caught: groovy.lang.MissingMethodException: No signature of method: 
> Sub.test3() is applicable for argument types: () values: {}
>         at Super.invokeMethod(test1.groovy)
>         at test1.run(test1.groovy:18)
>         at test1.main(test1.groovy)
> {code}
> I think that calling Sub.metaClass should not have such a sideeffect.
> The script should work with or without it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to