我执行一个函数 ( listOf(matchUid, first_name, gender, matchBio, age).any { it == null }
) 检查传入的任何变量是否为null
:
private fun getMatchData(doc: DocumentSnapshot){
val matchUid = if (isUser1) doc.getString("user2") else doc.getString("user1")
val first_name = if (isUser1) doc.getString("user2name") else doc.getString("user1name")
val gender = if (isUser1) doc.getString("user2gender") else doc.getString("gender")
val matchBio = if (isUser1) doc.getString("user2bio") else doc.getString("user1bio")
if ( listOf(matchUid, first_name, gender, matchBio, age).any { it == null } ) return goOffline()
if (matchUid == null) return goOffline()
if (!isUser1) Group = Group().apply {
id = doc.id
user1 = matchUid
user2 = user.uid
match = User(matchUid, first_name, gender, null, true)
}
即使它检查了这一点,first_name
并且gender
由于 null 安全性,编译器也有红色下划线。matchUid
没有红线,因为我在下面的行中明确检查了 null。
为什么我已经检查过编译器仍然给出空警告?