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/24 02:46:00 UTC
[jira] [Resolved] (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:all-tabpanel ]
Paul King resolved GROOVY-10635.
--------------------------------
Fix Version/s: 5.0.0-alpha-1
4.0.3
Resolution: Fixed
> 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
> Fix For: 5.0.0-alpha-1, 4.0.3
>
>
> 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)