Last active
March 24, 2021 04:11
-
-
Save mangei/11169675 to your computer and use it in GitHub Desktop.
groovy null list and empty list check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.geier | |
class IfTest { | |
public static void main(String[] args) { | |
List<String> emptyList = []; | |
List<String> nullList = null; | |
if (emptyList == null || emptyList.empty) { | |
println "AAA emptyList" | |
} | |
if (emptyList?.empty) { | |
println "BBB emptyList" | |
} | |
println "-----------------" | |
if (nullList == null || nullList.empty) { | |
println "AAA nullList" | |
} | |
if (nullList?.empty) { | |
println "BBB nullList" | |
} | |
} | |
} | |
// | |
// OUTPUT: | |
// AAA emptyList | |
// BBB emptyList | |
// ----------------- | |
// AAA nullList | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not using groovy truth?
if(nullList){...}
if(emptyList){...}
?