smallufo
12/28/2021, 5:57 PMfun getMap(): Map<String, String> {
return buildMap {
if (A) {
put(key, "A")
} else {
put(key, "B")
}
}
}
but after upgrade to kotlin 1.6 , compiler complains type mismatch :
Type mismatch.
Required:
Unit
Found:
String
Type mismatch.
Required:
Unit
Found:
TypeVariable(V)?
Type mismatch.
Required:
Unit
Found:
String?
I have to change to this style :
return buildMap {
put(key, if (A) "A" else "B")
}
It is OK but not so readable.
But why !?Ayfri
12/28/2021, 6:57 PMkey
?ilya.gorbunov
12/28/2021, 10:48 PMsmallufo
12/28/2021, 11:16 PM