Reputation: 6972
I was writing unit tests when I happened to find that in groovy the below is true
null.collect({ //Anything }) == []
I could not find the reason for this. What part of groovy is giving this behavior? I checked NullObject
but that does not have this collect method. So how is this happening?
Upvotes: 3
Views: 1514
Reputation: 16403
In groovy null
has the iterator()
method which returns an empty iterator. Calling collect
on null is the same as null.iterator().collect({/*whatever*/})
and so this will be []
.
See the comment on this bug report.
Upvotes: 2