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 2023/05/11 05:58:00 UTC

[jira] [Created] (GROOVY-11052) Explore using @Lazy with @Immutable/records

Paul King created GROOVY-11052:
----------------------------------

             Summary: Explore using @Lazy with @Immutable/records
                 Key: GROOVY-11052
                 URL: https://issues.apache.org/jira/browse/GROOVY-11052
             Project: Groovy
          Issue Type: Improvement
            Reporter: Paul King
            Assignee: Paul King


Currently, the following code:
{code}
record Foo(@Lazy String bar) { }

new Foo('Baz')
{code}
gives:
{noformat}
cannot modify final field '$bar' outside of constructor.
{noformat}

I was thinking of adding an explicit error, something along the lines of "@Lazy is not compatible with records".

The following also doesn't work:
{code}
@groovy.transform.Immutable
class Foo {
    @Lazy String bar
}
{code}
I think it is worthwhile exploring options to make this work for @Immutable classes.
Maybe making the field not final (it will be effectively final) and having a Closure<String> constructor option.




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