You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2017/05/02 02:04:14 UTC

[jira] [Closed] (GROOVY-1628) Inconsistent checking of final

     [ https://issues.apache.org/jira/browse/GROOVY-1628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-1628.
-----------------------------

> 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: Russel Winder
>            Assignee: Cédric Champeau
>             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
(v6.3.15#6346)