myanmarking
01/28/2022, 7:45 PMmyanmarking
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()myanmarking
01/28/2022, 7:45 PMout K there.myanmarking
01/28/2022, 7:50 PMtemp - 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.Joffrey
01/28/2022, 8:09 PMClearly 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.