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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With