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

Paul King commented on GROOVY-12315:
------------------------------------

Historically the docs (and code) say:

{quote}... inference never applies to fields even if a field is final ...{quote}

I don't think the JMM actually constrains things quite as much as that comment 
states. For final fields, perhaps there is more that we can do, but things do 
get tricky with collections/generic types. I suspect that would be a Groovy 7 
thing.

> Type for final field should be known by flow-typing
> ---------------------------------------------------
>
>                 Key: GROOVY-12315
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12315
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0-alpha-1, 5.0.3, 4.0.31
>            Reporter: Björn Kautler
>            Priority: Major
>
> This does not compile, while the type should be clear as the field is final:
> {code:java}
> @groovy.transform.CompileStatic
> class Foo {
>   final bar = ''
>   def foo() {
>     println(bar.length())
>   }
> }
> new Foo().foo() {code}
> With a local variable it works even without {{{}final{}}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to