groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David M. Karr" <>
Subject Unexpected use of "collection.field.first()"
Date Wed, 13 Jan 2016 18:38:18 GMT
Today I noticed an unexpected way the "first()" function behaves. I'd 
appreciate some clarification.

With the following data:

def data = [
   name : 'Ivan', age: 35,
   childs : [
     [name: 'Judith', age:8], [name: 'Adriana', age:5]

The following two statements produce the same result:

println data.childs.first().name

Being "Judith".

The first one is obvious to me.  The second one is unexpected. What's 
going on here exactly?

View raw message