Android kotlin多个字符串值进行判空
2021-12-29 本文已影响0人
为自己代颜_
fun String?.orStr(vararg otherStr: String?): String? {
var showStr: String? = null
if (this.isNullOrEmpty()) {
run outside@{
otherStr.forEach {
if (!it.isNullOrEmpty()) {
showStr = it
return@outside
}
}
}
} else {
showStr = this
}
return showStr
}
调用方法如下:
fun getShowGroupName(): String? {
return groupAlias.orStr(groupName, tempName)
}
过程中由groupAlias、groupName、tempName依次判空取值