groovy - Is if(!x) the same as if(x!=null) -
i know sort of duplicate of is if(pointervar) same if(pointervar!=null)?, have ask anyway.
in groovy, have following:
def x = somemethod() if( !x ) { // stuff }
this standard null
check, ie (x != null)
, right?
no. if
in groovy calls underlying asboolean()
method. known groovy truth.
empty lists, empty strings, empty maps, null, 0
, falsy values:
if ([:]) { assert false } if (null) { assert false } if ("") { assert false } if (0) { assert false } assert null.asboolean() == false assert 1.asboolean()
you can write asboolean
in own classes.
Comments
Post a Comment