A Scala library, I'm using in my Kotlin code, provides a function, which expects a scala.collection.immutable.Map<String!, String!>!
as an argument.
To have a minimal example, let's call this function f
. I'd like to the values of a given Kotlin map to it, but I'm struggling with the conversion:
fun f(x: scala.collection.immutable.Map<String, String>) {}
fun main() {
val m = mapOf("foo" to "bar")
val m2 = scala.jdk.CollectionConverters.MapHasAsScala(m).asScala()
f(m2)
}
Error:
Type mismatch.
Required:
scala.collection.immutable.Map<String, String>
Found:
scala.collection.mutable.Map<String!, String!>!
I understand, I should use .toMap
, but I'm not allowed to call this function without providing an ev
argument:
val m2 = scala.jdk.CollectionConverters.MapHasAsScala(m).asScala().toMap<String, String>()
Error:
No value passed for parameter 'ev'
What am I missing?