groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Theodorou (JIRA)" <>
Subject [jira] [Commented] (GROOVY-8320) Support property references in addition to the method references from Java 8
Date Sat, 16 Sep 2017 00:13:00 GMT


Jochen Theodorou commented on GROOVY-8320:

I think if that gets implemented it is likely to be a static feature only.take ´def boundReference
= test::property´.How would I know if the method property() or getProperty() is meant? which
has precendence and why? The static compiler could at least find out if there is a getProperty
and property method at the same time. But then, what should it do? Fail compilation, that
means to compile less than Java. Then not fail compilation and give the property() method
precedence? That is difficult for the user. So currently I don´t thik of this as a good idea.

> Support property references in addition to the method references from Java 8
> ----------------------------------------------------------------------------
>                 Key: GROOVY-8320
>                 URL:
>             Project: Groovy
>          Issue Type: Improvement
>          Components: parser-antlr
>    Affects Versions: 2.6.0-alpha-1
>            Reporter: David Kron
>            Priority: Minor
> It would be great if the method reference syntax from Java (Class::method or obj::method)
could also be extended to support Groovy properties. The new parser currently already parses
the syntax without error, but it gets treated as a method reference.
> Potential example usage:
> {code:java}
> class Test {
>     String property
> }
> def test = new Test(property: 'Hello')
> def boundReference = test::property
> def unboundReference = Test::property
> // getting/setting property using bound reference
> println boundReference.get()
> boundReference.set('Hello to you!')
> // getting/setting property using unbound reference
> println unboundReference.get(test)
> unboundReference.set(test, 'Hello to you!')
> // retrieving meta information
> println boundReference.type
> println
> println
> {code}

This message was sent by Atlassian JIRA

View raw message