Special Groovy access to magic re properties and / iterables collections?

I understand what is happening with the distribution operator *.in Groovy (2.4.3):

[].class.methods*.name
=> [add, add, remove, remove, get, ...

But why does the conclusion *give the same results?

[].class.methods.name
=> [add, add, remove, remove, get, ...

I expected this to be interpreted as accessing the property namefor java.lang.reflect.Method[]returned methods, and therefore be an error. But it seems to work. After that, experiment a little more, so do the following:

[*[].class.methods].name
=> [add, add, remove, remove, get, ...
([].class.methods.toList()).name
=> [add, add, remove, remove, get, ...

So, it seems that trying to access an array property or a list (possibly even Iterable) actually returns a list of this property for each list item (as an extension operator would do).

So this leaves me wondering:

UPDATE:

, *. Iterable, . . :

class Foo implements Iterable {
    public Iterator iterator() { [Long.class, String.class].iterator() }
}
(new Foo())*.name
=> [java.lang.Long, java.lang.String]
(new Foo()).name
=> groovy.lang.MissingPropertyException: No such property: name for class: Foo

( , : Iterable , () Iterable - .)

+4
1

, GPath (ish) , , . ( Ted Naleid , 2008 )

*. .collect()

. : Groovy -

( @NathanHughes

+5

All Articles