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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -