[ https://issues.apache.org/jira/browse/GROOVY-6747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-6747: -------------------------------- Fix Version/s: 2.5.16 > Problem With Anonymous Inner Enum > --------------------------------- > > Key: GROOVY-6747 > URL: https://issues.apache.org/jira/browse/GROOVY-6747 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.1.8, 2.4.0-rc-1 > Reporter: Jeff Brown > Assignee: Eric Milles > Priority: Major > Fix For: 3.0.8, 4.0.0-alpha-3, 2.5.16 > > Attachments: enumquestion.zip > > Time Spent: 0.5h > Remaining Estimate: 0h > > Related to http://jira.grails.org/browse/GRAILS-11348. > See the attached enumquestion.zip which demonstrates the behavior without > involving Grails. Run "./gradlew test" to see a relevant test failure. > {code:title=src/main/groovy/com/demo/SampleAppIndicatorCodes.groovy|borderStyle=solid} > package com.demo > public enum SampleAppIndicatorCodes { > YES("Y") { > @Override > public String getCode() { > return booleanCode; > } > }, > NO("N") { > @Override > public String getCode() { > return booleanCode; > } > }; > private String booleanCode = null > private SampleAppIndicatorCodes(String booleanCode) { > this.booleanCode = booleanCode > } > public abstract String getCode(); > public static SampleAppIndicatorCodes getSourceIndicator(String > booleanCode) { > if ("Y".equalsIgnoreCase(booleanCode)) { > return YES > } else if ("L".equalsIgnoreCase(booleanCode)) { > return NO > } else { > throw new IllegalArgumentException("No Indicator for the code > $booleanCode") > } > } > } > {code} > {code:title=src/test/groovy/com/demo/SampleAppIndicatorCodesSpec.groovy|borderStyle=solid} > package com.demo > import spock.lang.Specification > class SampleAppIndicatorCodesSpec extends Specification { > def 'test accessing YES code'() { > expect: > 'Y' == SampleAppIndicatorCodes.YES.code > } > } > {code} > For this particular case the anonymous inner classes seems like a peculiar > way to do this but in general apparently this syntax is supposed to be valid. > I ran this example by Jochen this morning and he felt like this is probably > a bug. -- This message was sent by Atlassian Jira (v8.20.1#820001)