Пример кода:
val map1: Map<String, DataClass> = ...
val map2: Map<String, DataClass> = ...
val result = map1 - map2
Тип result
обозначен как Map<Any, DataClass>
в Android Studio, что заставляет меня прибегнуть к:
val result = (map1 - map2).mapKeys { it.key.toString() }
Документация приводит меня кожидать сохранения типа K
как String
, или я что-то здесь упускаю?
/**
* Returns a map containing all entries of the original map except those entries
* the keys of which are contained in the given [keys] collection.
*
* The returned map preserves the entry iteration order of the original map.
*/
@SinceKotlin("1.1")
public operator fun <K, V> Map<out K, V>.minus(keys: Iterable<K>): Map<K, V> =
this.toMutableMap().apply { minusAssign(keys) }.optimizeReadOnlyMap()