Is it possible to remove the nullability of a gene...
# announcements
s
Is it possible to remove the nullability of a generic type? Sort of the opposite of
T?
. ie. here I invented the
!!
type operator for it. Should be clear from the example here why it makes sense.
Copy code
interface LoadingCache<K : Any, V> {
    fun get(key: K): V // <-- If it can return null then it must be specified by type V

    // If load returns null then entries are missing hence it doesnt make sense to have here : Map<K,V?>
    fun <MV : V!!> getAll(keys: Iterable<K>): Map<K, MV> {
        return keys.mapNotNull { k -> get(k)?.let { k to it } }.toMap()
    }
}