GROOVY学习 boolean

  刚开始自学GROOVY,总结一下:boolean值为false的情形有:变量未定义,null,false,整形0,浮点数0.0f,空字符串'',空List,空Map.刚刚接触Groovy,理解会有不足之处,大家补充一下啦..
//布尔值测试
def undefined;
def boolean_demo =[
	_undefined:undefined,
    _null:null,
    _false:false,
    _true:true,
    _int_0:0,
    _num_999:999,
    _float_0_0f:0.0f,
    _float_99_9f:99.9f,    
    _empty_str:'',
    _str_xxx:'xxx',
    _empty_list:[],
	_list:[0],    
    _empty_map:[:],
    _map:[0:0],
    _range:0..0,    
];

boolean_demo.each{map->
	println map.key + (map.value? " ===> true" : " ===> false");
};

输出结果如下:
_undefined ===> false
_null ===> false
_false ===> false
_true ===> true
_int_0 ===> false
_num_999 ===> true
_float_0_0f ===> false
_float_99_9f ===> true
_empty_str ===> false
_str_xxx ===> true
_empty_list ===> false
_list ===> true
_empty_map ===> false
_map ===> true
_range ===> true

你可能感兴趣的:(groovy)