Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.7.6, 1.8-beta-3
-
Fix Version/s: 1.8.5, 2.0-beta-2, 1.7.11
-
Component/s: Compiler
-
Labels:None
-
Number of attachments :
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
Issue Links
- relates to
-
GROOVY-4415
Error implementing a Java or Groovy generic interface
-
Activity
Paul King
made changes -
| Field | Original Value | New Value |
|---|---|---|
| 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 |
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: {code} 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 } */ } {code} {noformat} 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 {noformat} |
Cedric Champeau
made changes -
| Link |
This issue relates to |
Cedric Champeau
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Assignee | Cedric Champeau [ melix ] | |
| Fix Version/s | 2.0-beta-2 [ 18072 ] | |
| Fix Version/s | 1.7.11 [ 17244 ] | |
| Fix Version/s | 1.8.5 [ 18071 ] | |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |