i have a tiny question regarding the documentation...
# multiplatform
h
i have a tiny question regarding the documentation and the nature of the multiplatform way of working. https://kotlinlang.org/docs/reference/multiplatform.html if i create an expect function in the common code, and an actual in the JVM, from the JVM, can i also expect the actual function to exist, ergo call the actual function, which is in the JVM from JavaScript?
h
Just to make it clear: do you want your JS-targeted code to be able to access an implementation that is placed in a JVM-specific source set? Why this way, and why not place it in the common code, then? You can even create a source set that is shared just between the two targets.
j
No. Simply put, JavaScript has no JVM to execute anything on. The JavaScript and JVM sections of your code are part of different source sets that do not interact, meaning that those pieces of code have no effect on eachother. If you want to have one implementation used in all platforms, then you can just declare a normal function in Common. If you want to override that implementation in just one of the platforms, sorry, but you’re outta luck for right now. Kotlin has no support for that; you’ll have to write separate implementations for each platform.
h
so if i understand correctly, you mean an implemenation that happens to the likings of this: https://hastebin.com/ulamohawak.kt
h
you’ll have to write separate implementations for each platform
In fact, with the new Multiplatform Projects model, you can write just two implementations, one for a certain platform, and another for all the other platforms. You just have to put the second one in a source set that is directed to the compilations appropriately, as described here: kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets Even in that case, though, you may still need an expect declaration in the common sources which both the source sets holding the actuals see.
h
so was my proof of concept possible? I am not entirely sure. @h0tk3y
j
Nifty, I haven’t tried out the new model yet