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)