Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.7.6, 1.8-beta-3
-
None
Description
When attempting to compile the following groovy code I get the compiler error under groovy 1.7.6 and 1.8.3-beta-3. This has to do with defining an interface (or class) with getters and then defining properties (or final members variables) on a subclass using covariant returns. I can work around this issue by explicitly defining the required getter in the subclass which is rather annoying b/c I like groovy getter generation and in our codebase we are running into this a lot. This is also a problem when using "def" types. I would be glad to assist in any way if I can. Thanks.
For example:
interface CovariantReturns { Foo getGood() Object getBad() } class Foo {} class CovariantReturnsImpl implements CovariantReturns { //getter is generated by groovy as required by the interface final Foo good //this variable is defined as the subtype of Object final Foo bad /* I would expect that the following method would be generated by groovy which is using Java's covariant returns feature. Including the method below will allow the groovy compiler to succeed but is annoying that it has to be explicitly defined in code. public Foo getBad() { return bad } */ }
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: CovariantReturns.groovy: 8: Can't have an abstract method in a non-abstract class. The class 'CovariantReturns Impl' must be declared abstract or the method 'java.lang.Object getBad()' must be implemented. @ line 8, column 1. class CovariantReturnsImpl implements CovariantReturns { ^ 1 error
Attachments
Issue Links
- relates to
-
GROOVY-4415 Error implementing a Java or Groovy generic interface
- Closed