Spring on Rails encounters an un-Groovy limitation
One of the big selling points of Groovy is that a Groovy class is supposed to be able to do anything a Java class can. It was for this reason that we chose Groovy for “Spring on Rails”:http://thebogles.com/blog/2005/09/spring-on-rails/.
Unfortunately, it appear that this is not quite the case. For instance, Groovy classes in scripts cannot be used to extend abstract base classes– the example below will result in an AbstractMethodError from Java if you attempt to run it as a script.
If on the other hand, you compile the script using groovyc, it works as expected, but making that work correctly in our system is going to involve some unwanted hoops and change the way scripts are written.
I’m hoping this is simply a bug and not expected behavior; I’ve filed a bug in the Groovy JIRA database to describe it.
If this can’t be fixed, it makes me wonder whether we might be better off using JRuby as a scripting language. JRuby can’t extend abstract Java base classes either, but Ruby is a more mature and widely adopted scripting language.
---- Base.java ----------
abstract public class Base
{
abstract int foo();
}
---- Subclass.groovy----------
class Subclass1 extends Base
{
int foo() { return 1; }
}
Base b = new Subclass1();
System.out.println(b.foo());
2 Comments so far
Leave a comment
Its a bug and one that should be easy to fix. Which version of Groovy are you using?
By James Strachan on 10.04.05 2:21 am
This is using the latest release, 1.0-jsr-03.
By philbo on 10.04.05 3:35 pm
Leave a comment