hfhbd
11/05/2025, 11:14 AMnull in Map<String, String>.get(null): mapOf<String, String>("f" to "f").get(null as String?)Rob Elliot
11/05/2025, 11:53 AMpublic inline operator fun <@kotlin.internal.OnlyInputTypes K, V> Map<out K, V>.get(key: K): V? =
@Suppress("UNCHECKED_CAST") (this as Map<K, V>).get(key)
So you're doing an unchecked cast from Map<String, String> to Map<String?, String>ephemient
11/05/2025, 3:11 PMMap<K, out V> is invariant in K, but Java's interface defines (effectively) fun containsKey(Any?) and fun get(Any?). and it kind of makes sense that containsKey(!is K) == false and get(!is K) == nullRob Elliot
11/05/2025, 3:25 PMmapOf("f" to "f").get(1), though, that's a compile error, though it would work in Java. Presumably because there are no occasions when it could possibly return anything.
I guess that a key with type String? might be a String so might be able to be a key to an entry in a Map<String, String>, so it makes sense to accept it to that get extension function rather than force the caller to do mightBeNull?.let { notNull -> mapWithNotNullKeys[notNull] }.ephemient
11/05/2025, 3:28 PM"f" == 1 while it accepts "f" == null, so it is consistent