Check an object is a list or collection or array in Groovy fashion
Code:
boolean isCollectionOrArray(object) {
[Collection, Object[]].any { it.isAssignableFrom(object.getClass()) }
}
Unit Test
assert isCollectionOrArray([])
assert isCollectionOrArray([] as Set)
assert isCollectionOrArray([].toArray())
assert !isCollectionOrArray("a string")
A computer language which is concise, natural and human. Need to say more?