Search

Dark theme | Light theme

August 9, 2010

Groovy Goodness: Groovy Truth for Simple Type Arrays

Since Groovy 1.7.4 we can use simple type arrays in a conditional context. If the array is empty we get false, otherwise true is returned. Support for byte, short, int, long, float, double, char and boolean type arrays is added to Groovy. This functionality already worked for Object arrays, but now also for simple type arrays.

def bytes = [] as byte[]
def ints = [1,2,4] as int[]
def floats = [] as float[]
def booleans = [true, false] as boolean[]

assert !bytes
assert ints
assert !floats
assert booleans