myanmarking
01/28/2022, 7:45 PMval map: Map<String, Data> = ..
val temp = map - 1
public operator fun <K, V> Map<out K, V>.minus(key: K): Map<K, V> =
this.toMutableMap().apply { minusAssign(key) }.optimizeReadOnlyMap()
out K
there.temp - context
. It must be some compiler bug i guessJavier
01/28/2022, 7:56 PMmyanmarking
01/28/2022, 7:56 PMJoffrey
01/28/2022, 8:07 PMK
is then inferred to Any
for temp
. Try to add an explicit type for the temp
variable, you'll see that trying Map<String, Data>
shouldn't work.Clearly there isThis is exactly why you can do this. Athere.out K
Map<String, Data>
conforms to Map<out Any, Data>
, so you can call the minus
function with K=Any
on this Map<String, Data>
without issues.