Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Code Block
def numbers = [1,2,3]
assert numbers //true, as numbers in not empty
numbers = []
assert !numbers //false, as numbers is now an empty collection

Iterators and Enumerations

Iterators and Enumerations with no further elements are coerced to false.

Code Block

assert ![].iterator() // false because the Iterator is empty
assert [0].iterator() // true because the Iterator has a next element
def v = new Vector()
assert !v.elements()  // false because the Enumeration is empty
v.add(new Object())
assert v.elements()   // true because the Enumeration has more elements


Non-empty maps are coerced to true.