hallvard
11/03/2019, 9:41 PMDuplicate JVM class name
error from gradle when trying to build (and if I move my extension function to a file that has no expect
functions, everything is hunky dory).kpgalligan
11/03/2019, 10:06 PMSam
11/03/2019, 10:38 PMhallvard
11/03/2019, 10:46 PMpackage com.sannsyn.example
actual fun expectMeForDinner(): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
package com.sannsyn.example
import kotlin.js.JsName
open class John {
private val backing: Map<String, Any?>
@JsName("JohnFromMap")
constructor(map: Map<String, Any?>) {
require(map.isNotEmpty()) { "Cannot construct a John object from empty map." }
backing = map.toMap() // i.e. create a copy
}
}
expect fun expectMeForDinner(): String
// To get a John object out of a Map<String, *>:
public fun Map<String, Any?>.toJohn() = John(this)
kpgalligan
11/03/2019, 10:52 PMExtensionFunctionsJVM.kt
. Something like that. You can run into naming issues on the jvm as the compiler makes a class for the file when there are top level things, and an extension is that.hallvard
11/03/2019, 10:57 PMDico
11/05/2019, 12:16 PM