1.Optional类

Optional.of("123").ifPresent(e -> {
    // 不为空的话则执行下面代码
	});
// 返回布尔值
Optional<Object> o = Optional.ofNullable(null);
boolean present = o.isPresent();
// 为空则抛出异常
 Optional.of("123").orElseThrow(() -> new IllegalArgumentException("参数不能为空"));
// 为空则放入默认值
Optional.of("123").orElseGet(() -> "默认值");

2.断言

// 判断条件不成立 则抛出异常
Assert.state(ObjectUtil.isNotEmpty(dictDataDO), "字典不存在");

3.三元运算符

condition ? valueIfTrue : valueIfFalse
String result = StringUtils.isNotEmpty(str) ? "true" : "false";

4.Predicate类

// 将一个判断条件放入 Predicate 中
Predicate<Integer> a = e -> e > 0;
int c = 3;

// 调用 test 对象的方法进行判断
if(a.test(c)){
	System.out.println("true");
}else {
	System.out.println("false");
}

涩图time