Tuesday, 22 January 2019

Groovy: List in boolean context


Empty list evaluate to false, and non-empty list evaluates to true.

HelloWorld.groovy

emptyList = []
nonEmptyList = [null]

if(emptyList){
 println "emptyList evaluated to true"
}else{
 println "emptyList evaluated to false"
}

if(nonEmptyList){
 println "nonEmptyList evaluated to true"
}else{
 println "nonEmptyList evaluated to false"
}

Output
emptyList evaluated to false
nonEmptyList evaluated to true


Previous                                                 Next                                                 Home

No comments:

Post a Comment