hutool工具类库BooleanUtil类.isTrue(Boolean bool)方法
代码举例
private boolean tryLock(String key) {
Boolean flag = stringRedisTemplate.opsForValue().setIfAbsent(key, "1", 10, TimeUnit.SECONDS);
// 避免返回值为null,这里使用了BooleanUtil工具类
return BooleanUtil.isTrue(flag);
}
文档BooleanUtil类
https://plus.hutool.cn/apidocs/
isTrue
public static boolean isTrue(Boolean bool)
检查 Boolean 值是否为 true
- BooleanUtil.isTrue(Boolean.TRUE) = true
- BooleanUtil.isTrue(Boolean.FALSE) = false
- BooleanUtil.isTrue(null) = false
Parameters:
bool - 被检查的Boolean值
Returns:
当值为true且非null时返回true

浙公网安备 33010602011771号