我想创建一个类似于Kotlin的ifEmpty()的函数,该函数还将判断null:
ifNullOrEmpty{
//some code if null or empty
}
我该怎么做?
有人知道下面的代码叫什么吗?
: R where C : CharSequence, C : R
Kotlin ifEmpty()函数的示例.
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline fun <C, R> C.ifEmpty(defaultValue: () -> R): R where C : CharSequence, C : R =
if (isEmpty()) defaultValue() else this
谢谢,祝你今天愉快!