[
https://issues.apache.org/jira/browse/GROOVY-1628?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17136633#comment-17136633
]
Cédric Champeau commented on GROOVY-1628:
-----------------------------------------
The compiler is correct. You're using `set += XXX`. Note the "equals". You're
creating a new set and assigning it to the variable. The final variable is
therefore reassigned.
> Inconsistent checking of final
> ------------------------------
>
> Key: GROOVY-1628
> URL: https://issues.apache.org/jira/browse/GROOVY-1628
> Project: Groovy
> Issue Type: Sub-task
> Components: Compiler
> Environment: Ubuntu 6.10 Edgy Eft + Groovy r4630
> Reporter: Dr. Russel Winder
> Assignee: Cédric Champeau
> Priority: Major
> Fix For: 2.5.0-alpha-1
>
>
> The following code appears to show that final is being applied
> inconsistently. A final list can be amended but an object that manipulates a
> lsit that is final cannot. In the former case the final is being applied to
> the reference and in the later, it is being applied to the object.
> {code}
> class Blah {
> def list = []
> public plus ( item ) {
> list += [ item ]
> return this
> }
> }
> class Foobar {
> final static blah = new Blah ( )
> }
> final x = []
> x += [1]
> println ( x )
> Foobar.blah += 1
> println ( Foobar.blah.list )
> {code}
> |> groovy finalProblem.groovy
> [1]
> Caught: java.lang.IllegalAccessException: Field is final
> at finalProblem.run(finalProblem.groovy:17)
> at finalProblem.main(finalProblem.groovy)
--
This message was sent by Atlassian Jira
(v8.3.4#803005)