Collections and Maps evaluates to true if not null and not empty and false if null or empty
/* an empty map example*/
def userInfo = [:]
if (!userInfo)
userInfo << ['user': 'Groot', 'species' : 'unknown' ]
will add user: 'Groot' , species : 'unknown'
as default userInfo since the userInfo map is empty (note that the map is not null here)
With a null object, the code is lightly different, we cannot invoke << on userInfo because it is null, we have to make an assignment (refer also to Object boolean evaluation):
/* an example with a null object (def does not implies Map type) */
def userInfo = null
if (!userInfo)
userInfo = ['user': 'Groot', 'species' : 'unknown' ]
And with a null Map:
/* The same example with a null Map */
Map<String,String> userInfo = null
if (!userInfo)
userInfo = ['user': 'Groot', 'species' : 'unknown' ]