[ 
https://issues.apache.org/jira/browse/GROOVY-8116?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15907296#comment-15907296
 ] 

Paul King commented on GROOVY-8116:
-----------------------------------

My understanding is that final isn't implicit for enums like it is for 
interfaces. While it isn't an encouraged practice, I believe in Java you can 
technically make a non-final instance field and have a mutable enum instance. 
So, I think Groovy's current behavior is correct. Though I noticed that the 
getter method on a final property retains the final modifier - which we 
wouldn't normally do, though it isn't a big deal since inheritance of enums 
isn't supported.

> Property generation for enum is incorrect
> -----------------------------------------
>
>                 Key: GROOVY-8116
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8116
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>
> When creating a simple enum, I noticed that content assist was giving some 
> strange results.  It appears as though there is no special case handling for 
> properties in an enum.
> {code}
> enum Suit {
>   CLUBS(1),  SPADES(1), HEARTS(2), DIAMONDS(2);
>   int color
>   Suit(int color) {
>     this.color = color
>   }
> }
> {code}
> Since this is an enum, the final modifier on color should not be necessary -- 
> it is implied.  Java does not require it.  However the generated field does 
> not indicate final in the AST and a setter setColor is created.  I checked 
> this in the Groovy Console.
> {code}
> final public class Suit implements groovy.lang.GroovyObject extends 
> java.lang.Enum<Suit> { 
>     final public static Suit HEARTS 
>     final public static Suit DIAMONDS 
>     final public static Suit SPADES 
>     final public static Suit CLUBS 
>     private int color
>     ...
>     public int getColor() {
>     }
>     public void setColor(int value) {
>     }
> }
> {code}
> The method setColor is coming up in my IDE's content assist, since it is 
> generated by the Verifier.visitProperty method.  I think if the generated 
> fields are indicated as final for enums then Verifier will not generate 
> setters.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to