You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/07/14 16:29:00 UTC

[jira] [Commented] (GROOVY-9339) Compile-time-safe reflection access to field

    [ https://issues.apache.org/jira/browse/GROOVY-9339?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17743219#comment-17743219 ] 

Eric Milles commented on GROOVY-9339:
-------------------------------------

Like this?
{code:groovy}
class Data {
  public String field
}
def getter = (Data.&getProperty).rcurry('field')
def result = getter(new Data(field:'value'))
print result
{code}

> Compile-time-safe reflection access to field
> --------------------------------------------
>
>                 Key: GROOVY-9339
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9339
>             Project: Groovy
>          Issue Type: Wish
>            Reporter: Matthias Fuchs
>            Priority: Minor
>
> With groovy 3 we can get a reference to method like this:
>  
> {code:java}
> var valueOf = String::valueOf
> println(valueOf("a"))
> {code}
> It would be nice to have such a compile-time-safe reflective access to fields as well:
>  
>  
> {code:java}
> class Data {
>    private String field
> }
> def field = Data::field // 1
> def value = field.get(){code}
> This way the compiler would ensure that "field" is actually a real field and not cause *NoSuchFieldException*.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)