Kotlin

1. 使用 ?: Elvis 运算符

1
2
3
// 如果该变量不为 null,则执行 ?: Elvis 运算符之前的表达式;
// 如果变量为 null,则执行 ?: Elvis 运算符之后的表达式
val v = var1?.a ?: defaultValue