https://kotlinlang.org logo
#random
Title
i

IRomanov

05/30/2018, 9:36 AM
Thank you. Usually i have some flow around it, and I loop over the map anyway, and could filter null keys at the same time. But, I think, I will write such a helper-method, that delete null-key and make unsafe cast, because don't want to have unsafe cast warnings anywhere.
Copy code
@Suppress("UNCHECKED_CAST")
public inline fun <K : Any, V> Map<out K?, V>.filterNotNullKeys(): Map<K, V> =
    toMutableMap().apply { remove(null) }.toMap() as Map<K, V>