Paul King created GROOVY-10635:
----------------------------------

             Summary: Method references not working for record components in 
dynamic code
                 Key: GROOVY-10635
                 URL: https://issues.apache.org/jira/browse/GROOVY-10635
             Project: Groovy
          Issue Type: Bug
            Reporter: Paul King
            Assignee: Paul King


The following example currently fails.

{code}
record Bar(String name) { }

def bars = [new Bar(name: 'A'), new Bar(name: 'B')]
assert bars.stream().map(Bar::name).toList() == ['A', 'B']
{code}
The error message is:
{noformat}
java.lang.IllegalArgumentException: Can not set final java.lang.String field 
Bar.name to java.lang.Class
{noformat}
This is because the metaclass is picking the private field as a property ahead 
of the same-named accessor method.

Workaround is to use @CompileStatic.




--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to