jastrachan | 25 Feb 14:28 2005
Picon

Re: Does inheritance work in groovy

BTW you can only call 'super()' inside a constructor.  (We should trap  
this and generate a better error).

To call the super class inside a method, you have to do

   public void x() {
         super.x()
         println "This is another message"
     }

On 25 Feb 2005, at 13:20, Neil Mc Laughlin wrote:
> I've recently been trying out groovy for writing unittests. Version  
> info:
> Version: 1.0-beta-9 JVM: 1.5.0_01-b08.
>
> When I called super() in a method, I got an exception - Exception in  
> thread
> "main" java.lang.VerifyError: (class: Ab, method: x signature: ()V)
> Expecting to find unitialized object on stack
>  at java.lang.Class.forName0(Native Method)
>
> The following script demonstrates. Exception stack trace is below. Can  
> any
> one tell me where I'm going wrong?
>
>
> class Aa {
>     public void x(s) {
>         println "This is a message"
>     }
> }
>
> class Ab extends Aa {
>     public Ab() {
>         super()
>     }
>     public void x() {
>         super()
>         println "This is another message"
>     }
> }
>
> ab = new Ab()
> ab.x()
>
>
> Exception trace was
>
> bash-2.05b$ inheritance.groovy
> Exception in thread "main" java.lang.VerifyError: (class: Ab, method: x
> signature: ()V) Expecting to find unitialized object on stack
>  at java.lang.Class.forName0(Native Method)
>  at java.lang.Class.forName(Class.java:164)
>  at inheritance.class$(d:\home\nml\groovy\.\inheritance.groovy)
>  at inheritance.run(d:\home\nml\groovy\.\inheritance.groovy)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
>  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
>  at java.lang.reflect.Method.invoke(Method.java:585)
>  at
> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaM 
> ethod
> .java:67)
>  at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1401)
>  at groovy.lang.MetaClass.invokeMethod(MetaClass.java:319)
>  at groovy.lang.MetaClass.invokeMethod(MetaClass.java:304)
>  at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:143)
>  at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.ja 
> va:95
> )
>  at
> org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java: 
> 353)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
>  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
>  at java.lang.reflect.Method.invoke(Method.java:585)
>  at
> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaM 
> ethod
> .java:67)
>  at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1401)
>  at groovy.lang.MetaClass.invokeStaticMethod(MetaClass.java:468)
>  at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:117)
>  at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.ja 
> va:95
> )
>  at inheritance.main(d:\home\nml\groovy\.\inheritance.groovy)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
>  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
>  at java.lang.reflect.Method.invoke(Method.java:585)
>  at
> org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaM 
> ethod
> .java:67)
>  at groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1401)
>  at groovy.lang.MetaClass.invokeStaticMethod(MetaClass.java:468)
>  at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:117)
>  at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.ja 
> va:95
> )
>  at  
> groovy.lang.GroovyShell.runMainOrTestOrRunnable(GroovyShell.java:307)
>  at groovy.lang.GroovyShell.run(GroovyShell.java:235)
>  at groovy.lang.GroovyShell.run(GroovyShell.java:163)
>  at groovy.ui.GroovyMain.processOnce(GroovyMain.java:366)
>  at groovy.ui.GroovyMain.run(GroovyMain.java:232)
>  at groovy.ui.GroovyMain.process(GroovyMain.java:218)
>  at groovy.ui.GroovyMain.main(GroovyMain.java:122)
>  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
>  at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
>  at java.lang.reflect.Method.invoke(Method.java:585)
>  at org.codehaus.classworlds.Launcher.launchStandard(Launcher.java:410)
>  at org.codehaus.classworlds.Launcher.launch(Launcher.java:344)
>  at org.codehaus.classworlds.Launcher.main(Launcher.java:461)
> bash-2.05b$
>
>
> Regards,
> Neil
>
>

James
-------
http://radio.weblogs.com/0112098/


Gmane