You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2022/05/23 12:46:00 UTC
[jira] [Commented] (GROOVY-10635) Method references not working for record components in dynamic code
[ https://issues.apache.org/jira/browse/GROOVY-10635?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17540936#comment-17540936 ]
ASF GitHub Bot commented on GROOVY-10635:
-----------------------------------------
paulk-asert opened a new pull request, #1721:
URL: https://github.com/apache/groovy/pull/1721
…dynamic code
> 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
> Priority: Major
>
> 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)