



Android Kotlin - viewBinding Type mismatch: inferred type is DrawerLayout but ConstraintLayout was expected.This always applies unless you want to tell the difference between keys that aren't in the map and keys that are in the map but associated null values (which is quite rare).Īll in all, I would write something like that: fun main() but Any was expected However, it's smart enough to understand a null check if you simply get the value first and then check for null. The compiler cannot see the correlation between containsKey and the subsequent get or access. Maps return null for keys that are not associated with any value (this is why you need to check for null after getting the value). This would save you all the casts on the final values.Īnother point I'd like to make is that if you access the value for a key anyway, you don't need to check up front the existence of the key with containsKey. (you could obviously add more properties if need be) For instance, in your case, the class for your main map's values could be the following: data class PackageInfo( I'm a bit late to the party, but I'd like to point out another solution here.Īs I commented on the OP, heterogeneous maps with fixed string keys like this are usually better expressed with classes in Kotlin.
