is there any difference between the below function...
# getting-started
j
is there any difference between the below function signatures -
Copy code
fun <T, K, M : MutableMap<in K, in T>> Iterable<T>.associateByTo(destination: M, keySelector: (T) -> K): M
&
Copy code
fun <T, K> Iterable<T>.associateByTo(destination: MutableMap<in K, in T>, keySelector: (T) -> K): MutableMap<in K, in T>
y
The 2nd tells you that it returns the same exact map type that you gave in. Thus, if you pass in a HashMap, you get a HashMap and vice verse
j
[slightly edited the 2nd example to change the return type from Map to MutableMap to make the signatures more equivalent] i assume you meant
1st
returns the same exact type which makes sense (since it returns
M
).
y
Sorry yes typo. The 1st basically tells you that, unless there's reflection trickery going on, the return value will always be
destination
, as in the same exact reference
j
thanks, got it