Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.7.6
-
Fix Version/s: 2.0.8, 2.1.3, 2.2.0-beta-1
-
Component/s: Compiler
-
Labels:None
-
Environment:Mac OS X 10.6.6
IntelliJ 10.0.1
-
Testcase included:yes
-
Number of attachments :
Description
In Java you can define abstract methods for an enum type to override it with a concrete method in a constant-specific class body (see Effective Java, 2nd Ed., page 152). When I try to do the same in Groovy I get a compilation error:
Can't have an abstract method in a non-abstract class. The class 'Day' must be declared abstract or the method 'java.lang.String getAction()' must be implemented.
This compilation error can be reproduced with this enum:
enum Day { SUNDAY { String getAction() { 'Relax' } }, MONDAY { String getAction() { 'Work' } } abstract String getAction() }
An enum in Groovy should provide the same behavior for enums as Java.
Activity
Paul King
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
In Java you can define abstract methods for an enum type to override it with a concrete method in a constant-specific class body (see Effective Java, 2nd Ed., page 152). When I try to do the same in Groovy I get a compilation error:
Can't have an abstract method in a non-abstract class. The class 'Day' must be declared abstract or the method 'java.lang.String getAction()' must be implemented. This compilation error can be reproduced with this enum: enum Day { SUNDAY { String getAction() { 'Relax' } }, MONDAY { String getAction() { 'Work' } } abstract String getAction() } An enum in Groovy should provide the same behavior for enums as Java. |
In Java you can define abstract methods for an enum type to override it with a concrete method in a constant-specific class body (see Effective Java, 2nd Ed., page 152). When I try to do the same in Groovy I get a compilation error:
Can't have an abstract method in a non-abstract class. The class 'Day' must be declared abstract or the method 'java.lang.String getAction()' must be implemented. This compilation error can be reproduced with this enum: {code} enum Day { SUNDAY { String getAction() { 'Relax' } }, MONDAY { String getAction() { 'Work' } } abstract String getAction() } {code} An enum in Groovy should provide the same behavior for enums as Java. |
Paul King
made changes -
| Assignee | Paul King [ paulk ] |
Paul King
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | 2.0.8 [ 19099 ] | |
| Fix Version/s | 2.1.3 [ 19156 ] | |
| Fix Version/s | 2.2.0-beta-1 [ 19074 ] | |
| Resolution | Fixed [ 1 ] |
Paul King
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
add code tags