How comes I can't create an extension function on ...
# announcements
g
How comes I can't create an extension function on Map with multiple signatures? https://pl.kotl.in/i5aSCMMgj but also I can't use Any, Any, so I'm not sure what's the best way to do it?
NM I figured it out
Copy code
fun <T, E> Map<T, E>.toArgString(): String = map { "${it.key}=${it.value}" }.joinToString("&")
a
You can annotate extension methods with
@JvmName
to prevent the method naming clash. And in this case you can just use
Map<*, *>.toArgString()
since you don’t really care what T or E are
Map<String, Any>
would work too (or
Map<String, Any?>
) — the key parameter to
Map
is invariant, which is why
Map<Any,Any>
doesn’t work (but
Map<*,*>
works around that)
g
Thanks @araqnid!