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 2022/05/23 12:13:00 UTC

[jira] [Created] (GROOVY-10635) Method references not working for record components in dynamic code

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)