Details
-
Sub-task
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
None
Description
Java enum allows instance (value) specific methods. Groovy does not support this currently. The following code fails in Groovy (compilation error):
class GroovyEnumRangeTest extends GroovyTestCase {
void testEnumMethod()
}
enum Day {
SUNDAY {
String activity()
}, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
String activity()
{ 'Work' }}
If I need it right now, I am able to use EMC to achieve this:
class GroovyEnumRangeTest extends GroovyTestCase
{
void testEnumMethod()
{
def emc = new ExpandoMetaClass(Day)
emc.activity = {-> 'Relax' }
emc.initialize()
Day.SUNDAY.metaClass = emc
assertEquals "Work", Day.MONDAY.activity()
assertEquals "Relax", Day.SUNDAY.activity()
assertEquals "Work", Day.TUESDAY.activity()
}
}
enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
String activity() { 'Work' }
}
so it is not major (IMHO).
Attachments
Attachments
Issue Links
- depends upon
-
GROOVY-69 support inner classes (or at least nested classes)
- Closed
- is duplicated by
-
GROOVY-3178 Dont support method override in enum
- Closed
-
GROOVY-3408 Groovy does not support abstract methods in enums
- Closed