I'm using the Grails 2.3.8 build system to build my Grails project (i.e., the default system built on top of Gant).
When I annotate my methods with @java.lang.Override, Grails doesn't fail compilation even if the method overrides nothing in the parent classes.
When I compile directly using groovyc, things work fine.
Is there a compilation option I haven't enabled? :)
Grails 2.3.8 uses Groovy 2.1.9. In that version of Groovy the @Override annotation is not honored in (at least) the situation I was using it (the most basic case):
class A {
def foo() {}
}
class B extends A {
@Override
def foo(String s) {}
}
In that version of Groovy (2.1.9) the above code compiles just fine.
Then I downloaded the latest version of Groovy (as of now, 2.4.1) and tried compiling the same class. The compiler threw an error as I expected:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
foo.groovy: 7: Method 'foo' from class 'B' does not override method from its superclass or interfaces but is annotated with @Override.
@ line 7, column 2.
@Override
^
1 error
UPDATE: There actually are two ways in which even Groovy 2.1.9 honors @Override:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With